This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

View File

@@ -20,68 +20,108 @@ static const TCHAR *kPanelsInfoValueName = TEXT("Panels");
static const TCHAR *kToolbars = TEXT("Toolbars");
static const TCHAR *kPanelPathValueName = TEXT("PanelPath");
static const TCHAR *kListMode = TEXT("ListMode");
static const TCHAR *kFolderHistoryValueName = TEXT("FolderHistory");
static const TCHAR *kFastFoldersValueName = TEXT("FolderShortcuts");
static const TCHAR *kCopyHistoryValueName = TEXT("CopyHistory");
#pragma pack( push, PragmaColumnInfoSpec)
#pragma pack( push, 1)
/*
class CColumnInfoSpec
{
UINT32 PropID;
BYTE IsVisible;
UINT32 Width;
public:
void GetFromColumnInfo(const CColumnInfo &aSrc)
{
PropID = aSrc.PropID;
IsVisible = aSrc.IsVisible ? 1: 0;
Width = aSrc.Width;
}
void PutColumnInfo(CColumnInfo &aDest)
{
aDest.PropID = PropID;
aDest.IsVisible = (IsVisible != 0);
aDest.Width = Width;
}
UInt32 PropID;
Byte IsVisible;
UInt32 Width;
};
struct CColumnHeader
{
UINT32 Version;
// UINT32 SortIndex;
UINT32 SortID;
BYTE Ascending;
UInt32 Version;
UInt32 SortID;
Byte Ascending;
};
*/
#pragma pack(pop)
#pragma pack(pop, PragmaColumnInfoSpec)
static const UInt32 kColumnInfoSpecHeader = 12;
static const UInt32 kColumnHeaderSize = 12;
static const UINT32 kColumnInfoVersion = 0;
static const UInt32 kColumnInfoVersion = 1;
static NSynchronization::CCriticalSection g_RegistryOperationsCriticalSection;
class CTempOutBufferSpec
{
CByteBuffer Buffer;
UInt32 Size;
UInt32 Pos;
public:
operator const Byte *() const { return (const Byte *)Buffer; }
void Init(UInt32 dataSize)
{
Buffer.SetCapacity(dataSize);
Size = dataSize;
Pos = 0;
}
void WriteByte(Byte value)
{
if (Pos >= Size)
throw "overflow";
((Byte *)Buffer)[Pos++] = value;
}
void WriteUInt32(UInt32 value)
{
for (int i = 0; i < 4; i++)
{
WriteByte((Byte)value);
value >>= 8;
}
}
void WriteBool(bool value)
{
WriteUInt32(value ? 1 : 0);
}
};
class CTempInBufferSpec
{
public:
Byte *Buffer;
UInt32 Size;
UInt32 Pos;
Byte ReadByte()
{
if (Pos >= Size)
throw "overflow";
return Buffer[Pos++];
}
UInt32 ReadUInt32()
{
UInt32 value = 0;
for (int i = 0; i < 4; i++)
value |= (((UInt32)ReadByte()) << (8 * i));
return value;
}
bool ReadBool()
{
return (ReadUInt32() != 0);
}
};
void SaveListViewInfo(const CSysString &id, const CListViewInfo &viewInfo)
{
const CObjectVector<CColumnInfo> &columns = viewInfo.Columns;
CByteBuffer buffer;
UINT32 dataSize = sizeof(CColumnHeader) + sizeof(CColumnInfoSpec) * columns.Size();
buffer.SetCapacity(dataSize);
BYTE *dataPointer = (BYTE *)buffer;
CColumnHeader &columnHeader = *(CColumnHeader *)dataPointer;
columnHeader.Version = kColumnInfoVersion;
CTempOutBufferSpec buffer;
UInt32 dataSize = kColumnHeaderSize + kColumnInfoSpecHeader * columns.Size();
buffer.Init(dataSize);
// columnHeader.SortIndex = viewInfo.SortIndex;
columnHeader.SortID = viewInfo.SortID;
columnHeader.Ascending = viewInfo.Ascending ? 1 : 0;
CColumnInfoSpec *destItems = (CColumnInfoSpec *)(dataPointer + sizeof(CColumnHeader));
buffer.WriteUInt32(kColumnInfoVersion);
buffer.WriteUInt32(viewInfo.SortID);
buffer.WriteBool(viewInfo.Ascending);
for(int i = 0; i < columns.Size(); i++)
{
CColumnInfoSpec &columnInfoSpec = destItems[i];
columnInfoSpec.GetFromColumnInfo(columns[i]);
const CColumnInfo &column = columns[i];
buffer.WriteUInt32(column.PropID);
buffer.WriteBool(column.IsVisible);
buffer.WriteUInt32(column.Width);
}
{
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
@@ -90,7 +130,7 @@ void SaveListViewInfo(const CSysString &id, const CListViewInfo &viewInfo)
keyName += kCulumnsKeyName;
CKey key;
key.Create(HKEY_CURRENT_USER, keyName);
key.SetValue(id, dataPointer, dataSize);
key.SetValue(id, (const Byte *)buffer, dataSize);
}
}
@@ -99,7 +139,7 @@ void ReadListViewInfo(const CSysString &id, CListViewInfo &viewInfo)
viewInfo.Clear();
CObjectVector<CColumnInfo> &columns = viewInfo.Columns;
CByteBuffer buffer;
UINT32 size;
UInt32 size;
{
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
CSysString keyName = kCUBasePath;
@@ -111,49 +151,52 @@ void ReadListViewInfo(const CSysString &id, CListViewInfo &viewInfo)
if (key.QueryValue(id, buffer, size) != ERROR_SUCCESS)
return;
}
if (size < sizeof(CColumnHeader))
if (size < kColumnHeaderSize)
return;
BYTE *dataPointer = (BYTE *)buffer;
const CColumnHeader &columnHeader = *(CColumnHeader*)dataPointer;
if (columnHeader.Version != kColumnInfoVersion)
return;
viewInfo.Ascending = (columnHeader.Ascending != 0);
CTempInBufferSpec inBuffer;
inBuffer.Size = size;
inBuffer.Buffer = (Byte *)buffer;
inBuffer.Pos = 0;
// viewInfo.SortIndex = columnHeader.SortIndex;
viewInfo.SortID = columnHeader.SortID;
size -= sizeof(CColumnHeader);
if (size % sizeof(CColumnHeader) != 0)
UInt32 version = inBuffer.ReadUInt32();
if (version != kColumnInfoVersion)
return;
int numItems = size / sizeof(CColumnInfoSpec);
CColumnInfoSpec *specItems = (CColumnInfoSpec *)(dataPointer + sizeof(CColumnHeader));;
viewInfo.SortID = inBuffer.ReadUInt32();
viewInfo.Ascending = inBuffer.ReadBool();
size -= kColumnHeaderSize;
if (size % kColumnInfoSpecHeader != 0)
return;
int numItems = size / kColumnInfoSpecHeader;
columns.Reserve(numItems);
for(int i = 0; i < numItems; i++)
{
CColumnInfo columnInfo;
specItems[i].PutColumnInfo(columnInfo);
columnInfo.PropID = inBuffer.ReadUInt32();
columnInfo.IsVisible = inBuffer.ReadBool();
columnInfo.Width = inBuffer.ReadUInt32();
columns.Add(columnInfo);
}
}
#pragma pack( push, PragmaWindowPosition)
#pragma pack( push, 1)
static const UInt32 kWindowPositionHeaderSize = 5 * 4;
static const UInt32 kPanelsInfoHeaderSize = 3 * 4;
/*
struct CWindowPosition
{
RECT Rect;
UINT32 Maximized;
UInt32 Maximized;
};
struct CPanelsInfo
{
UINT32 NumPanels;
UINT32 CurrentPanel;
UINT32 SplitterPos;
UInt32 NumPanels;
UInt32 CurrentPanel;
UInt32 SplitterPos;
};
#pragma pack(pop)
#pragma pack(pop, PragmaWindowPosition)
*/
void SaveWindowSize(const RECT &rect, bool maximized)
{
@@ -161,10 +204,15 @@ void SaveWindowSize(const RECT &rect, bool maximized)
CKey key;
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
key.Create(HKEY_CURRENT_USER, keyName);
CWindowPosition position;
position.Rect = rect;
position.Maximized = maximized ? 1: 0;
key.SetValue(kPositionValueName, &position, sizeof(position));
// CWindowPosition position;
CTempOutBufferSpec buffer;
buffer.Init(kWindowPositionHeaderSize);
buffer.WriteUInt32(rect.left);
buffer.WriteUInt32(rect.top);
buffer.WriteUInt32(rect.right);
buffer.WriteUInt32(rect.bottom);
buffer.WriteBool(maximized);
key.SetValue(kPositionValueName, (const Byte *)buffer, kWindowPositionHeaderSize);
}
bool ReadWindowSize(RECT &rect, bool &maximized)
@@ -175,31 +223,39 @@ bool ReadWindowSize(RECT &rect, bool &maximized)
if(key.Open(HKEY_CURRENT_USER, keyName, KEY_READ) != ERROR_SUCCESS)
return false;
CByteBuffer buffer;
UINT32 size;
UInt32 size;
if (key.QueryValue(kPositionValueName, buffer, size) != ERROR_SUCCESS)
return false;
if (size != sizeof(CWindowPosition))
if (size != kWindowPositionHeaderSize)
return false;
const CWindowPosition &position = *(const CWindowPosition *)(const BYTE *)buffer;
rect = position.Rect;
maximized = (position.Maximized != 0);
CTempInBufferSpec inBuffer;
inBuffer.Size = size;
inBuffer.Buffer = (Byte *)buffer;
inBuffer.Pos = 0;
rect.left = inBuffer.ReadUInt32();
rect.top = inBuffer.ReadUInt32();
rect.right = inBuffer.ReadUInt32();
rect.bottom = inBuffer.ReadUInt32();
maximized = inBuffer.ReadBool();
return true;
}
void SavePanelsInfo(UINT32 numPanels, UINT32 currentPanel, UINT32 splitterPos)
void SavePanelsInfo(UInt32 numPanels, UInt32 currentPanel, UInt32 splitterPos)
{
CSysString keyName = kCUBasePath;
CKey key;
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
key.Create(HKEY_CURRENT_USER, keyName);
CPanelsInfo block;
block.NumPanels = numPanels;
block.CurrentPanel = currentPanel;
block.SplitterPos = splitterPos;
key.SetValue(kPanelsInfoValueName, &block, sizeof(block));
CTempOutBufferSpec buffer;
buffer.Init(kPanelsInfoHeaderSize);
buffer.WriteUInt32(numPanels);
buffer.WriteUInt32(currentPanel);
buffer.WriteUInt32(splitterPos);
key.SetValue(kPanelsInfoValueName, (const Byte *)buffer, kPanelsInfoHeaderSize);
}
bool ReadPanelsInfo(UINT32 &numPanels, UINT32 &currentPanel, UINT32 &splitterPos)
bool ReadPanelsInfo(UInt32 &numPanels, UInt32 &currentPanel, UInt32 &splitterPos)
{
CSysString keyName = kCUBasePath;
CKey key;
@@ -207,19 +263,22 @@ bool ReadPanelsInfo(UINT32 &numPanels, UINT32 &currentPanel, UINT32 &splitterPos
if(key.Open(HKEY_CURRENT_USER, keyName, KEY_READ) != ERROR_SUCCESS)
return false;
CByteBuffer buffer;
UINT32 size;
UInt32 size;
if (key.QueryValue(kPanelsInfoValueName, buffer, size) != ERROR_SUCCESS)
return false;
if (size != sizeof(CPanelsInfo))
if (size != kPanelsInfoHeaderSize)
return false;
const CPanelsInfo &block = *(const CPanelsInfo *)(const BYTE *)buffer;
numPanels = block.NumPanels;
currentPanel = block.CurrentPanel;
splitterPos = block.SplitterPos;
CTempInBufferSpec inBuffer;
inBuffer.Size = size;
inBuffer.Buffer = (Byte *)buffer;
inBuffer.Pos = 0;
numPanels = inBuffer.ReadUInt32();
currentPanel = inBuffer.ReadUInt32();
splitterPos = inBuffer.ReadUInt32();
return true;
}
void SaveToolbarsMask(UINT32 toolbarMask)
void SaveToolbarsMask(UInt32 toolbarMask)
{
CKey key;
key.Create(HKEY_CURRENT_USER, kCUBasePath);
@@ -228,48 +287,73 @@ void SaveToolbarsMask(UINT32 toolbarMask)
static const kDefaultToolbarMask = 8 | 4 | 1;
UINT32 ReadToolbarsMask()
UInt32 ReadToolbarsMask()
{
CKey key;
if(key.Open(HKEY_CURRENT_USER, kCUBasePath, KEY_READ) != ERROR_SUCCESS)
return kDefaultToolbarMask;
UINT32 mask;
UInt32 mask;
if (key.QueryValue(kToolbars, mask) != ERROR_SUCCESS)
return kDefaultToolbarMask;
return mask;
}
static CSysString GetPanelPathName(UINT32 panelIndex)
static CSysString GetPanelPathName(UInt32 panelIndex)
{
TCHAR panelString[32];
ConvertUINT64ToString(panelIndex, panelString);
ConvertUInt64ToString(panelIndex, panelString);
return CSysString(kPanelPathValueName) + panelString;
}
void SavePanelPath(UINT32 panel, const CSysString &path)
void SavePanelPath(UInt32 panel, const CSysString &path)
{
CSysString keyName = kCUBasePath;
CKey key;
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
key.Create(HKEY_CURRENT_USER, keyName);
key.Create(HKEY_CURRENT_USER, kCUBasePath);
key.SetValue(GetPanelPathName(panel), path);
}
bool ReadPanelPath(UINT32 panel, CSysString &path)
bool ReadPanelPath(UInt32 panel, CSysString &path)
{
CSysString keyName = kCUBasePath;
CKey key;
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
if(key.Open(HKEY_CURRENT_USER, keyName, KEY_READ) != ERROR_SUCCESS)
if(key.Open(HKEY_CURRENT_USER, kCUBasePath, KEY_READ) != ERROR_SUCCESS)
return false;
return (key.QueryValue(GetPanelPathName(panel), path) == ERROR_SUCCESS);
}
void SaveListMode(const CListMode &listMode)
{
CKey key;
key.Create(HKEY_CURRENT_USER, kCUBasePath);
UInt32 t = 0;
for (int i = 0; i < 2; i++)
t |= ((listMode.Panels[i]) & 0xFF) << (i * 8);
key.SetValue(kListMode, t);
}
void ReadListMode(CListMode &listMode)
{
CKey key;
listMode.Init();
if(key.Open(HKEY_CURRENT_USER, kCUBasePath, KEY_READ) != ERROR_SUCCESS)
return;
UInt32 t;
if (key.QueryValue(kListMode, t) != ERROR_SUCCESS)
return;
for (int i = 0; i < 2; i++)
{
listMode.Panels[i] = (t & 0xFF);
t >>= 8;
}
}
void SaveStringList(LPCTSTR valueName, const UStringVector &folders)
{
UINT32 sizeInChars = 0;
UInt32 sizeInChars = 0;
int i;
for (i = 0; i < folders.Size(); i++)
sizeInChars += folders[i].Length() + 1;
@@ -295,12 +379,12 @@ void ReadStringList(LPCTSTR valueName, UStringVector &folders)
if(key.Open(HKEY_CURRENT_USER, kCUBasePath, KEY_READ) != ERROR_SUCCESS)
return;
CByteBuffer buffer;
UINT32 dataSize;
UInt32 dataSize;
if (key.QueryValue(valueName, buffer, dataSize) != ERROR_SUCCESS)
return;
if (dataSize % sizeof(wchar_t) != 0)
return;
const wchar_t *data = (const wchar_t *)(const BYTE *)buffer;
const wchar_t *data = (const wchar_t *)(const Byte *)buffer;
int sizeInChars = dataSize / sizeof(wchar_t);
UString string;
for (int i = 0; i < sizeInChars; i++)