| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "WinConfiguration.h"
- #include "Common.h"
- #include "Bookmarks.h"
- #include "Terminal.h"
- #include "TextsWin.h"
- #include "WinInterface.h"
- #include "GUITools.h"
- #include <stdio.h>
- #include <ResourceModule.hpp>
- #include <InitGUID.h>
- #include <DragExt.h>
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- //---------------------------------------------------------------------------
- const char ShellCommandFileNamePattern[] = "!.!";
- //---------------------------------------------------------------------------
- __fastcall TWinConfiguration::TWinConfiguration(): TCustomWinConfiguration()
- {
- FDDExtInstalled = -1;
- FBookmarks = new TBookmarks();
- FCustomCommands = new TCustomCommands();
- Default();
- try
- {
- CheckTranslationVersion(GetResourceModule(ModuleFileName().c_str()));
- }
- catch(...)
- {
- LocaleSafe = InternalLocale();
- }
- }
- //---------------------------------------------------------------------------
- __fastcall TWinConfiguration::~TWinConfiguration()
- {
- if (!FTemporarySessionFile.IsEmpty()) DeleteFile(FTemporarySessionFile);
- ClearTemporaryLoginData();
- delete FBookmarks;
- delete FCustomCommands;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::Default()
- {
- TCustomWinConfiguration::Default();
- FDDAllowMove = false;
- FDDTransferConfirmation = true;
- FDDTemporaryDirectory = "";
- FDDWarnLackOfTempSpace = true;
- FDDWarnLackOfTempSpaceRatio = 1.1;
- FDDExtEnabled = true;
- FDDExtTimeout = 1000;
- FDDExtCopySlipTimeout = 100;
- FDeleteToRecycleBin = true;
- FSelectDirectories = false;
- FSelectMask = "*.*";
- FShowHiddenFiles = true;
- FShowInaccesibleDirectories = true;
- FConfirmDeleting = true;
- FConfirmClosingSession = true;
- FConfirmExitOnCompletion = true;
- FForceDeleteTempFolder = true;
- FCopyOnDoubleClick = false;
- FCopyOnDoubleClickConfirmation = false;
- FDimmHiddenFiles = true;
- FAutoStartSession = "";
- FExpertMode = true;
- FUseLocationProfiles = false;
- FEditor.Editor = edInternal;
- FEditor.ExternalEditor = "notepad.exe";
- FEditor.FontName = "Courier New";
- FEditor.FontHeight = -12;
- FEditor.FontStyle = 0;
- FEditor.FontCharset = DEFAULT_CHARSET;
- FEditor.WordWrap = false;
- FEditor.FindText = "";
- FEditor.ReplaceText = "";
- FEditor.FindMatchCase = false;
- FEditor.FindWholeWord = false;
- FLogWindowOnStartup = true;
- FLogWindowParams = "-1;-1;500;400";
- FScpExplorer.WindowParams = "-1;-1;600;400;0";
- FScpExplorer.DirViewParams = "0;1;0|150,1;70,1;101,1;79,1;62,1;55,1|0;1;2;3;4;5";
- FScpExplorer.CoolBarLayout = "5,0,0,94,6;1,1,0,638,5;4,0,0,239,4;3,1,0,424,3;6,1,0,206,2;2,1,1,634,1;0,1,1,634,0";
- FScpExplorer.StatusBar = true;
- AnsiString PersonalFolder;
- SpecialFolderLocation(CSIDL_PERSONAL, PersonalFolder);
- FScpExplorer.LastLocalTargetDirectory = PersonalFolder;
- FScpExplorer.ViewStyle = 0; /* vsIcon */
- FScpExplorer.ShowFullAddress = true;
- FScpCommander.WindowParams = "-1;-1;600;400;0";
- FScpCommander.LocalPanelWidth = 0.5;
- FScpCommander.StatusBar = true;
- FScpCommander.ToolBar = true;
- FScpCommander.CommandLine = false;
- FScpCommander.ExplorerStyleSelection = false;
- FScpCommander.PreserveLocalDirectory = false;
- FScpCommander.CoolBarLayout = "5,0,0,219,6;1,1,0,319,5;4,0,0,227,4;3,1,0,136,3;6,1,0,121,2;2,1,1,67,1;0,1,1,649,0";
- FScpCommander.CurrentPanel = osLocal;
- FScpCommander.CompareByTime = true;
- FScpCommander.CompareBySize = false;
- FScpCommander.SynchronizeBrowsing = false;
- FScpCommander.RemotePanel.DirViewParams = "0;1;0|150,1;70,1;101,1;79,1;62,1;55,0|0;1;2;3;4;5";
- FScpCommander.RemotePanel.StatusBar = true;
- FScpCommander.RemotePanel.CoolBarLayout = "2,1,0,137,2;1,1,0,86,1;0,1,1,91,0";
- FScpCommander.LocalPanel.DirViewParams = "0;1;0|150,1;70,1;101,1;79,1;62,1;55,0|0;1;2;3;4;5";
- FScpCommander.LocalPanel.StatusBar = true;
- FScpCommander.LocalPanel.CoolBarLayout = "2,1,0,137,2;1,1,0,86,1;0,1,1,91,0";
- FBookmarks->Clear();
- FCustomCommands->Clear();
- FCustomCommands->Values[LoadStr(CUSTOM_COMMAND_EXECUTE)] = "\"!\"";
- FCustomCommands->Params[LoadStr(CUSTOM_COMMAND_EXECUTE)] = 0;
- FCustomCommands->Values[LoadStr(CUSTOM_COMMAND_TOUCH)] = "touch \"!\"";
- FCustomCommands->Params[LoadStr(CUSTOM_COMMAND_TOUCH)] = ccApplyToDirectories | ccRecursive;
- FCustomCommands->Values[LoadStr(CUSTOM_COMMAND_MOVE)] =
- FORMAT("mv \"!\" \"!?%s?!\"", (LoadStr(CUSTOM_COMMAND_MOVE_PARAM)));
- FCustomCommands->Params[LoadStr(CUSTOM_COMMAND_MOVE)] = ccApplyToDirectories;
- FCustomCommandsModified = false;
- }
- //---------------------------------------------------------------------------
- TStorage __fastcall TWinConfiguration::GetStorage()
- {
- if (FStorage == stDetect)
- {
- if (FindResourceEx(NULL, RT_RCDATA, "WINSCP_SESSION",
- MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL)))
- {
- FTemporarySessionFile = GetTemporaryPath() + "winscp3s.tmp";
- DumpResourceToFile("WINSCP_SESSION", FTemporarySessionFile);
- FEmbeddedSessions = true;
- FTemporaryKeyFile = GetTemporaryPath() + "winscp3k.tmp";
- if (!DumpResourceToFile("WINSCP_KEY", FTemporaryKeyFile))
- {
- FTemporaryKeyFile = "";
- }
- }
- }
- return TCustomWinConfiguration::GetStorage();
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::ModifyAll()
- {
- TCustomWinConfiguration::ModifyAll();
- FBookmarks->ModifyAll(true);
- FCustomCommandsModified = true;
- }
- //---------------------------------------------------------------------------
- THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool SessionList)
- {
- if (SessionList && !FTemporarySessionFile.IsEmpty())
- {
- return new TIniFileStorage(FTemporarySessionFile);
- }
- else
- {
- return TCustomWinConfiguration::CreateScpStorage(SessionList);
- }
- }
- //---------------------------------------------------------------------------
- // duplicated from core\configuration.cpp
- #define LASTELEM(ELEM) \
- ELEM.SubString(ELEM.LastDelimiter(".>")+1, ELEM.Length() - ELEM.LastDelimiter(".>"))
- #define BLOCK(KEY, CANCREATE, BLOCK) \
- if (Storage->OpenSubKey(KEY, CANCREATE)) try { BLOCK } __finally { Storage->CloseSubKey(); }
- #define REGCONFIG(CANCREATE) \
- BLOCK("Interface", CANCREATE, \
- KEY(Bool, CopyOnDoubleClick); \
- KEY(Bool, CopyOnDoubleClickConfirmation); \
- KEY(Bool, DDAllowMove); \
- KEY(Bool, DDTransferConfirmation); \
- KEY(String, DDTemporaryDirectory); \
- KEY(Bool, DDWarnLackOfTempSpace); \
- KEY(Float, DDWarnLackOfTempSpaceRatio); \
- KEY(Bool, DeleteToRecycleBin); \
- KEY(Bool, DimmHiddenFiles); \
- KEY(Bool, SelectDirectories); \
- KEY(String, SelectMask); \
- KEY(Bool, ShowHiddenFiles); \
- KEY(Bool, ShowInaccesibleDirectories); \
- KEY(Bool, ConfirmDeleting); \
- KEY(Bool, ConfirmClosingSession); \
- KEY(Bool, ConfirmExitOnCompletion); \
- KEY(String, AutoStartSession); \
- KEY(Bool, UseLocationProfiles); \
- KEY(Bool, ForceDeleteTempFolder); \
- KEY(Integer, LocaleSafe); \
- KEY(Bool, DDExtEnabled); \
- KEY(Integer, DDExtTimeout); \
- KEY(Integer, DDExtCopySlipTimeout); \
- ); \
- BLOCK("Interface\\Editor", CANCREATE, \
- KEY(Integer, Editor.Editor); \
- KEY(String, Editor.ExternalEditor); \
- KEY(String, Editor.FontName); \
- KEY(Integer, Editor.FontHeight); \
- KEY(Integer, Editor.FontStyle); \
- KEY(Integer, Editor.FontCharset); \
- KEY(Bool, Editor.WordWrap); \
- KEY(String, Editor.FindText); \
- KEY(String, Editor.ReplaceText); \
- KEY(Bool, Editor.FindMatchCase); \
- KEY(Bool, Editor.FindWholeWord); \
- ); \
- BLOCK("Interface\\Explorer", CANCREATE, \
- KEY(String, ScpExplorer.CoolBarLayout); \
- KEY(String, ScpExplorer.DirViewParams); \
- KEY(String, ScpExplorer.LastLocalTargetDirectory); \
- KEY(Bool, ScpExplorer.StatusBar); \
- KEY(String, ScpExplorer.WindowParams); \
- KEY(Integer, ScpExplorer.ViewStyle); \
- KEY(Bool, ScpExplorer.ShowFullAddress); \
- ); \
- BLOCK("Interface\\Commander", CANCREATE, \
- KEY(String, ScpCommander.CoolBarLayout); \
- KEY(Integer, ScpCommander.CurrentPanel); \
- KEY(Float, ScpCommander.LocalPanelWidth); \
- KEY(Bool, ScpCommander.StatusBar); \
- KEY(Bool, ScpCommander.CommandLine); \
- KEY(Bool, ScpCommander.ToolBar); \
- KEY(String, ScpCommander.WindowParams); \
- KEY(Bool, ScpCommander.ExplorerStyleSelection); \
- KEY(Bool, ScpCommander.PreserveLocalDirectory); \
- KEY(Bool, ScpCommander.CompareByTime); \
- KEY(Bool, ScpCommander.CompareBySize); \
- KEY(Bool, ScpCommander.SynchronizeBrowsing); \
- ); \
- BLOCK("Interface\\Commander\\LocalPanel", CANCREATE, \
- KEY(String, ScpCommander.LocalPanel.CoolBarLayout); \
- KEY(String, ScpCommander.LocalPanel.DirViewParams); \
- KEY(Bool, ScpCommander.LocalPanel.StatusBar); \
- ); \
- BLOCK("Interface\\Commander\\RemotePanel", CANCREATE, \
- KEY(String, ScpCommander.RemotePanel.CoolBarLayout); \
- KEY(String, ScpCommander.RemotePanel.DirViewParams); \
- KEY(Bool, ScpCommander.RemotePanel.StatusBar); \
- ); \
- BLOCK("Logging", CANCREATE, \
- KEY(Bool, LogWindowOnStartup); \
- KEY(String, LogWindowParams); \
- );
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SaveSpecial(THierarchicalStorage * Storage)
- {
- TCustomWinConfiguration::SaveSpecial(Storage);
- // duplicated from core\configuration.cpp
- #define KEY(TYPE, VAR) Storage->Write ## TYPE(LASTELEM(AnsiString(#VAR)), VAR)
- REGCONFIG(true);
- #undef KEY
- if (Storage->OpenSubKey("Bookmarks", true))
- {
- FBookmarks->Save(Storage);
- Storage->CloseSubKey();
- }
- if (FCustomCommandsModified)
- {
- if (Storage->OpenSubKey("CustomCommands", true))
- {
- Storage->WriteValues(FCustomCommands, true);
- Storage->CloseSubKey();
- }
- if (Storage->OpenSubKey("CustomCommandsParams", true))
- {
- Storage->ClearValues();
- for (int Index = 0; Index < FCustomCommands->Count; Index++)
- {
- Storage->WriteInteger(FCustomCommands->Names[Index],
- FCustomCommands->Params[FCustomCommands->Names[Index]]);
- }
- Storage->CloseSubKey();
- }
- FCustomCommandsModified = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::LoadSpecial(THierarchicalStorage * Storage)
- {
- TCustomWinConfiguration::LoadSpecial(Storage);
- // duplicated from core\configuration.cpp
- #define KEY(TYPE, VAR) VAR = Storage->Read ## TYPE(LASTELEM(AnsiString(#VAR)), VAR)
- #pragma warn -eas
- REGCONFIG(false);
- #pragma warn +eas
- #undef KEY
- if (Storage->OpenSubKey("Bookmarks", false))
- {
- FBookmarks->Load(Storage);
- Storage->CloseSubKey();
- }
- if (Storage->OpenSubKey("CustomCommands", false))
- {
- FCustomCommands->Clear();
- Storage->ReadValues(FCustomCommands, true);
- Storage->CloseSubKey();
- if (Storage->OpenSubKey("CustomCommandsParams", false))
- {
- for (int Index = 0; Index < FCustomCommands->Count; Index++)
- {
- AnsiString Name = FCustomCommands->Names[Index];
- FCustomCommands->Params[Name] =
- Storage->ReadInteger(Name, FCustomCommands->Params[Name]);
- }
- Storage->CloseSubKey();
- }
- }
- else if (FCustomCommandsModified)
- {
- FCustomCommands->Clear();
- }
- FCustomCommandsModified = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::LoadAdmin(THierarchicalStorage * Storage)
- {
- TConfiguration::LoadAdmin(Storage);
- FDisableOpenEdit = Storage->ReadBool("DisableOpenEdit", FDisableOpenEdit);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::ClearTemporaryLoginData()
- {
- if (!FTemporaryKeyFile.IsEmpty())
- {
- DeleteFile(FTemporaryKeyFile);
- FTemporaryKeyFile = "";
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::DumpResourceToFile(
- const AnsiString ResName, const AnsiString FileName)
- {
- HRSRC Resource;
- Resource = FindResourceEx(NULL, RT_RCDATA, ResName.c_str(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
- if (Resource)
- {
- unsigned long Size = SizeofResource(NULL, Resource);
- if (!Size)
- {
- throw Exception(FORMAT("Cannot get size of resource %s", (ResName)));
- }
- void * Content = LoadResource(NULL, Resource);
- if (!Content)
- {
- throw Exception(FORMAT("Cannot read resource %s", (ResName)));
- }
- Content = LockResource(Content);
- if (!Content)
- {
- throw Exception(FORMAT("Cannot lock resource %s", (ResName)));
- }
- FILE * f = fopen(FileName.c_str(), "wb");
- if (!f)
- {
- throw Exception(FORMAT("Cannot create file %s", (FileName)));
- }
- if (fwrite(Content, 1, Size, f) != Size)
- {
- throw Exception(FORMAT("Cannot write to file %s", (FileName)));
- }
- fclose(f);
- }
- return (Resource != NULL);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::RestoreForm(AnsiString Data, TCustomForm * Form)
- {
- assert(Form);
- if (!Data.IsEmpty())
- {
- TRect Bounds = Form->BoundsRect;
- Bounds.Left = StrToIntDef(::CutToChar(Data, ';', true), Bounds.Left);
- Bounds.Top = StrToIntDef(::CutToChar(Data, ';', true), Bounds.Top);
- Bounds.Right = StrToIntDef(::CutToChar(Data, ';', true), Bounds.Right);
- Bounds.Bottom = StrToIntDef(::CutToChar(Data, ';', true), Bounds.Bottom);
- TWindowState State = (TWindowState)StrToIntDef(::CutToChar(Data, ';', true), (int)wsNormal);
- ((TForm*)Form)->WindowState = State;
- if (State == wsNormal)
- {
- if (Bounds.Width() > Screen->Width) Bounds.Right -= (Bounds.Width() - Screen->Width);
- if (Bounds.Height() > Screen->Height) Bounds.Bottom -= (Bounds.Height() - Screen->Height);
- Form->BoundsRect = Bounds;
- #define POS_RANGE(x, prop) (x < 0) || (x > Screen->prop)
- if (POS_RANGE(Bounds.Left, Width - 20) || POS_RANGE(Bounds.Top, Height - 40))
- {
- ((TForm*)Form)->Position = poDefaultPosOnly;
- }
- else
- {
- ((TForm*)Form)->Position = poDesigned;
- }
- #undef POS_RANGE
- }
- }
- else if (((TForm*)Form)->Position == poDesigned)
- {
- ((TForm*)Form)->Position = poDefaultPosOnly;
- }
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TWinConfiguration::StoreForm(TCustomForm * Form)
- {
- assert(Form);
- return FORMAT("%d;%d;%d;%d;%d", ((int)Form->BoundsRect.Left, (int)Form->BoundsRect.Top,
- (int)Form->BoundsRect.Right, (int)Form->BoundsRect.Bottom,
- (int)Form->WindowState));
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::GetDDExtInstalled()
- {
- if (FDDExtInstalled < 0)
- {
- void* DragExtRef;
- bool Result;
- Result = (CoCreateInstance(CLSID_ShellExtension, NULL,
- CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown,
- &DragExtRef) == S_OK);
- FDDExtInstalled = (Result ? 1 : 0);
- }
- return (FDDExtInstalled > 0);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetLogWindowOnStartup(bool value)
- {
- SET_CONFIG_PROPERTY(LogWindowOnStartup);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetLogWindowParams(AnsiString value)
- {
- SET_CONFIG_PROPERTY(LogWindowParams);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDAllowMove(bool value)
- {
- SET_CONFIG_PROPERTY(DDAllowMove);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDTransferConfirmation(bool value)
- {
- SET_CONFIG_PROPERTY(DDTransferConfirmation);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDTemporaryDirectory(AnsiString value)
- {
- SET_CONFIG_PROPERTY(DDTemporaryDirectory);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDExtEnabled(bool value)
- {
- SET_CONFIG_PROPERTY(DDExtEnabled);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDExtTimeout(int value)
- {
- SET_CONFIG_PROPERTY(DDExtTimeout);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDDExtCopySlipTimeout(int value)
- {
- SET_CONFIG_PROPERTY(DDExtCopySlipTimeout);
- }
- //---------------------------------------------------------------------------
- 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::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::SetShowInaccesibleDirectories(bool value)
- {
- SET_CONFIG_PROPERTY(ShowInaccesibleDirectories);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetConfirmDeleting(bool value)
- {
- SET_CONFIG_PROPERTY(ConfirmDeleting);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetUseLocationProfiles(bool value)
- {
- SET_CONFIG_PROPERTY(UseLocationProfiles);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetConfirmClosingSession(bool value)
- {
- SET_CONFIG_PROPERTY(ConfirmClosingSession);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetConfirmExitOnCompletion(bool value)
- {
- SET_CONFIG_PROPERTY(ConfirmExitOnCompletion);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetForceDeleteTempFolder(bool value)
- {
- SET_CONFIG_PROPERTY(ForceDeleteTempFolder);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetCopyOnDoubleClick(bool value)
- {
- SET_CONFIG_PROPERTY(CopyOnDoubleClick);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetCopyOnDoubleClickConfirmation(bool value)
- {
- SET_CONFIG_PROPERTY(CopyOnDoubleClickConfirmation);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetDimmHiddenFiles(bool value)
- {
- SET_CONFIG_PROPERTY(DimmHiddenFiles);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetAutoStartSession(AnsiString value)
- {
- SET_CONFIG_PROPERTY(AutoStartSession);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetExpertMode(bool value)
- {
- SET_CONFIG_PROPERTY(ExpertMode);
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetCustomCommands(TCustomCommands * value)
- {
- assert(FCustomCommands);
- if (!FCustomCommands->Equals(value))
- {
- FCustomCommands->Assign(value);
- FCustomCommandsModified = true;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetBookmarks(AnsiString Key,
- TBookmarkList * value)
- {
- FBookmarks->Bookmarks[Key] = value;
- Changed();
- }
- //---------------------------------------------------------------------------
- TBookmarkList * __fastcall TWinConfiguration::GetBookmarks(AnsiString Key)
- {
- return FBookmarks->Bookmarks[Key];
- }
- //---------------------------------------------------------------------------
- void TWinConfiguration::ReformatFileNameCommand(AnsiString & Command)
- {
- AnsiString Program, Params, Dir;
- SplitCommand(Command, Program, Params, Dir);
- if (Params.Pos(ShellCommandFileNamePattern) == 0)
- {
- Params = Params + (Params.IsEmpty() ? "" : " ") + ShellCommandFileNamePattern;
- }
- Command = FormatCommand(Program, Params);
- }
- //---------------------------------------------------------------------------
- AnsiString __fastcall TWinConfiguration::GetDefaultKeyFile()
- {
- return FTemporaryKeyFile;
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- class TAsInheritedReader : public TReader
- {
- public:
- __fastcall TAsInheritedReader(TStream * Stream, int BufSize) :
- TReader(Stream, BufSize)
- {
- OnAncestorNotFound = AncestorNotFound;
- }
- virtual void __fastcall ReadPrefix(TFilerFlags & Flags, int & AChildPos)
- {
- TReader::ReadPrefix(Flags, AChildPos);
- Flags << ffInherited;
- }
- void __fastcall AncestorNotFound(TReader * Reader,
- const AnsiString ComponentName, TMetaClass * ComponentClass,
- TComponent *& Component)
- {
- assert(!Component);
- if (ComponentName.IsEmpty())
- {
- for (int Index = 0; Index < LookupRoot->ComponentCount; Index++)
- {
- Component = LookupRoot->Components[Index];
- if (Component->Name.IsEmpty())
- {
- return;
- }
- }
- Component = NULL;
- }
- }
- };
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::InternalReloadComponentRes(const AnsiString ResName,
- HANDLE HInst, TComponent * Instance)
- {
- HANDLE HRsrc;
- bool Result;
- if (!HInst)
- {
- HInst = HInstance;
- }
- HRsrc = FindResource(HInst, ResName.c_str(), RT_RCDATA);
- Result = (HRsrc != 0);
- if (Result)
- {
- TResourceStream * ResStream = new TResourceStream(
- reinterpret_cast<int>(HInst), ResName, RT_RCDATA);
- try
- {
- TReader * Reader;
- Reader = new TAsInheritedReader(ResStream, 4096);
- try
- {
- /*Instance =*/ Reader->ReadRootComponent(Instance);
- }
- __finally
- {
- delete Reader;
- }
- }
- __finally
- {
- delete ResStream;
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TWinConfiguration::InitComponent(TComponent * Instance,
- TClass RootAncestor, TClass ClassType)
- {
- bool Result = false;
- if ((ClassType != __classid(TComponent)) && (ClassType != RootAncestor))
- {
- if (InitComponent(Instance, RootAncestor, ClassType->ClassParent()))
- {
- Result = true;
- }
- if (InternalReloadComponentRes(ClassType->ClassName(),
- reinterpret_cast<HANDLE>(FindResourceHInstance(FindClassHInstance(ClassType))),
- Instance))
- {
- Result = true;
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- LCID __fastcall TWinConfiguration::GetLocale()
- {
- if (!FLocale)
- {
- AnsiString ResourceModule = GetResourceModule(ModuleFileName().c_str());
- if (!ResourceModule.IsEmpty())
- {
- AnsiString ResourceExt = ExtractFileExt(ResourceModule).UpperCase();
- ResourceExt.Delete(1, 1);
- TLanguages * Langs = Languages();
- int Index, Count;
- Count = Langs->Count;
- Index = 0;
- while ((Index < Count) && !FLocale)
- {
- if (Langs->Ext[Index] == ResourceExt)
- {
- FLocale = Langs->LocaleID[Index];
- }
- else if (Langs->Ext[Index].SubString(1, 2) == ResourceExt)
- {
- FLocale = MAKELANGID(PRIMARYLANGID(Langs->LocaleID[Index]),
- SUBLANG_DEFAULT);
- }
- Index++;
- }
- }
- }
- return TCustomWinConfiguration::GetLocale();
- }
- //---------------------------------------------------------------------------
- HANDLE __fastcall TWinConfiguration::LoadNewResourceModule(LCID ALocale,
- AnsiString * FileName)
- {
- AnsiString FileNameStorage;
- if (FileName == NULL)
- {
- FileName = &FileNameStorage;
- }
- HANDLE Instance = TCustomWinConfiguration::LoadNewResourceModule(ALocale, FileName);
- if (Instance != NULL)
- {
- try
- {
- CheckTranslationVersion(*FileName);
- }
- catch(...)
- {
- FreeResourceModule(Instance);
- throw;
- }
- }
- return Instance;
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::SetResourceModule(HANDLE Instance)
- {
- TCustomWinConfiguration::SetResourceModule(Instance);
- Busy(true);
- try
- {
- int Count;
- AnsiString OrigName;
- int OrigLeft;
- int OrigTop;
- TForm * Form;
- Count = Screen->FormCount;
- for (int Index = 0; Index < Count; Index++)
- {
- Form = Screen->Forms[Index];
- SendMessage(Form->Handle, WM_LOCALE_CHANGE, 0, 1);
- }
- ConfigureInterface();
- for (int Index = 0; Index < Count; Index++)
- {
- TComponent * Component;
- for (int Index = 0; Index < Form->ComponentCount; Index++)
- {
- Component = Form->Components[Index];
- if (dynamic_cast<TFrame*>(Component))
- {
- OrigName = Component->Name;
- InitComponent(Component, __classid(TFrame), Component->ClassType());
- Component->Name = OrigName;
- }
- }
- OrigLeft = Form->Left;
- OrigTop = Form->Top;
- OrigName = Form->Name;
- InitComponent(Form, __classid(TForm), Form->ClassType());
- Form->Name = OrigName;
- Form->Position = poDesigned;
- Form->Left = OrigLeft;
- Form->Top = OrigTop;
- SendMessage(Form->Handle, WM_LOCALE_CHANGE, 1, 1);
- }
- TDataModule * DataModule;
- Count = Screen->DataModuleCount;
- for (int Index = 0; Index < Count; Index++)
- {
- DataModule = Screen->DataModules[Index];
- OrigName = DataModule->Name;
- InitComponent(DataModule, __classid(TDataModule), DataModule->ClassType());
- DataModule->Name = OrigName;
- }
- }
- __finally
- {
- Busy(false);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TWinConfiguration::CheckTranslationVersion(const AnsiString FileName)
- {
- AnsiString TranslationProductVersion = GetFileProductVersion(FileName);
- AnsiString TranslationProductName = GetFileProductName(FileName);
- if ((ProductName != TranslationProductName) ||
- (ProductVersion != TranslationProductVersion))
- {
- if (TranslationProductName.IsEmpty() || TranslationProductVersion.IsEmpty())
- {
- throw Exception(FMTLOAD(UNKNOWN_TRANSLATION, (FileName)));
- }
- else
- {
- throw Exception(FMTLOAD(INCOMPATIBLE_TRANSLATION,
- (FileName, TranslationProductName, TranslationProductVersion)));
- }
- }
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- int __fastcall TCustomCommands::GetParam(const AnsiString & Name)
- {
- int Index = IndexOfName(Name);
- if (Index >= 0)
- {
- return int(Objects[Index]);
- }
- else
- {
- return 0;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomCommands::SetParam(const AnsiString & Name, int value)
- {
- int Index = IndexOfName(Name);
- if (Index >= 0)
- {
- Objects[Index] = (TObject *)value;
- }
- else
- {
- Values[Name] = "";
- Index = IndexOfName(Name);
- assert(Index >= 0);
- Objects[Index] = (TObject *)value;
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TCustomCommands::Equals(TCustomCommands * Commands)
- {
- bool Result = TStringList::Equals(Commands);
- if (Result)
- {
- int Index = 0;
- while ((Index < Count) && Result)
- {
- if (Objects[Index] != Commands->Objects[Index])
- {
- Result = false;
- }
- Index++;
- }
- }
- return Result;
- }
|