Skip to content

Commit

Permalink
Some code clean up. Intermediate shell.dll registry support
Browse files Browse the repository at this point in the history
  • Loading branch information
prokushev committed Nov 6, 2023
1 parent 161f66f commit 24c598a
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 186 deletions.
73 changes: 56 additions & 17 deletions dlls/shell/Registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ static void ReadSetupReg()
LPKEYSTRUCT lpKeyStruct;
HKEY hk;

if (!GetWindowsDirectory(buf,_MAX_PATH))
getcwd(buf,_MAX_PATH);
lstrcat(buf,"/setup.reg");
if ((hf = _lopen(buf,READ)) == HFILE_ERROR)
return;
dwFileSize = _llseek(hf,0,2);
lpBuffer = (LPSTR) GlobalAllocPtr(GPTR, dwFileSize+2);
_llseek(hf,0,0);
_lread(hf,lpBuffer,dwFileSize);
_lclose(hf);

ptr = lpBuffer;
if (!GetWindowsDirectory(buf,_MAX_PATH)) getcwd(buf,_MAX_PATH);
if (buf[lstrlen(buf)-1]!='\\') lstrcat(buf, "\\");
lstrcat(buf,"setup.reg");

if ((hf = _lopen(buf,READ)) == HFILE_ERROR) return;
dwFileSize = _llseek(hf,0,2);
lpBuffer = (LPSTR) GlobalAllocPtr(GPTR, dwFileSize+2);
_llseek(hf,0,0);
_lread(hf,lpBuffer,dwFileSize);
_lclose(hf);

ptr = lpBuffer;
while (i < dwFileSize) {
while ((lpBuffer[i] != '\n') && (i < dwFileSize))
i++;
Expand Down Expand Up @@ -105,11 +105,54 @@ static inline void fix_win16_hkey( HKEY *hkey )
if (*hkey == 0 || *hkey == (HKEY)1) *hkey = HKEY_CLASSES_ROOT;
}

static WORD StringHash(LPCSTR str)
{
WORD i, hash = 0;
LPDATHEADER lpDatHeader;

// TRACE("%x, %s, %x\n", entries, str, len);

lpDatHeader=(LPDATHEADER)GlobalLock(Globals.Registry);

for (i = 0; i < lstrlen(str); i++) hash ^= AnsiUpperChar(str[i]);
hash=hash % lpDatHeader->hashsize;
GlobalUnlock(Globals.Registry);
return hash;
}

static void AddString(LPCSTR str)
{
LPDATHEADER lpDatHeader;
LPDATNAVIGATION lpDatNavigation[1];
WORD hash=StringHash(str);

lpDatHeader=(LPDATHEADER)GlobalLock(Globals.Registry);

lpDatNavigation=(LPDATNAVIGATION)GlobalLock(Globals.EntryTable);
if (lpDatNavigation[hash+1]==hash+1) // Empty busket, so create new string
{
lpDatHeader->dwEntries++; // Add one more entry for string info
GlobalUnlock(Globals.EntryTable); // Allocate memory for it
GlobalReAlloc(Globals.EntryTable, lpDatHeader->dwEntries*sizeof(LPDATNAVIGATION), GMEM_MOVEABLE)
lpDatNavigation=(LPDATNAVIGATION)GlobalLock(Globals.EntryTable);
// Fill string information entry
lpDatNavigation[lpDatHeader->dwEntries]->length=lstrlen(str);
// Allocame memory for string
}

GlobalUnlock(Globals.EntryTable);
GlobalUnlock(Globals.Registry);
}

static BOOL InitReg()
{
LPDATNAVIGATION lpDatNavigation[1];
lpDatNavigation=(LPDATNAVIGATION)GlobalLock(Globals.EntryTable);
GlobalUnlock(Globals.EntryTable);

RootKey.hParentKey = (HKEY)0L;
if (!RootKey.atomKey)
RootKey.atomKey = AddAtomEx(&AtomTable,"HKEY_CLASSES_ROOT");
RootKey.atomKey = AddAtomEx(&AtomTable,".classes");
RootKey.fOpen = TRUE;
fRegInitialized = TRUE;
ReadSetupReg();
Expand Down Expand Up @@ -470,10 +513,6 @@ RegQueryValueEx

#endif





static LPKEYSTRUCT
InternalFindKey(LPKEYSTRUCT lpKeyStruct, LPCSTR lpszSubKey, WORD wFlag)
{
Expand Down
49 changes: 48 additions & 1 deletion dlls/shell/Shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ BOOL WINAPI LibMain( HINSTANCE hInstance, WORD wDataSegment, WORD wHeapSize, LPS
lstrcat(szPath, szFilename);

if ((Globals.EntryTable=GlobalAlloc(GMEM_MOVEABLE | GMEM_DISCARDABLE | GMEM_LOWER, 0)) &
(Globals.StringTable=GlobalAlloc(GMEM_MOVEABLE | GMEM_DISCARDABLE | GMEM_LOWER, 0)))
(Globals.StringTable=GlobalAlloc(GMEM_MOVEABLE | GMEM_DISCARDABLE | GMEM_LOWER, 0)) &
(Globals.Registry=GlobalAlloc(GMEM_MOVEABLE | GMEM_DISCARDABLE | GMEM_LOWER, 0)))
{
if ((hfRegistry=_lopen(szPath, 0))==HFILE_ERROR)
{
Expand All @@ -92,6 +93,7 @@ BOOL WINAPI LibMain( HINSTANCE hInstance, WORD wDataSegment, WORD wHeapSize, LPS
_lclose(hfRegistry);
UnlockResource(hRegistry);
FreeResource(hRegistry);
InitReg;
return TRUE;
}
_lclose(hfRegistry);
Expand All @@ -118,7 +120,52 @@ BOOL WINAPI LibMain( HINSTANCE hInstance, WORD wDataSegment, WORD wHeapSize, LPS
int WINAPI WEP( int bSystemExit )
#pragma on (unreferenced);
{
char szPath[MAX_PATH];
char szFilename[MAX_PATH];
HFILE hfRegistry;
LPSTR lpRegistry;

// Save regfile here
if ((GetWindowsDirectory(szPath, sizeof(szPath))) &
(LoadString(Globals.hInstance, IDS_REGISTRY, szFilename, sizeof(szFilename))))
{
if (szPath[lstrlen(szPath)-1]!='\\') lstrcat(szPath, "\\");
lstrcat(szPath, szFilename);

// save header
lpRegistry=GlobalLock(Globals.Registry);
if ((hfRegistry=_lcreat(szPath, 0))!=HFILE_ERROR)
{
if (_lwrite(hfRegistry, lpRegistry, GlobalSize(Globals.Registry))!=HFILE_ERROR)
{
_lclose(hfRegistry);
}
_lclose(hfRegistry);
}
GlobalUnlock(Globals.Registry);
// save table
lpRegistry=GlobalLock(Globals.EntryTable);
if ((hfRegistry=_lcreat(szPath, 0))!=HFILE_ERROR)
{
if (_lwrite(hfRegistry, lpRegistry, GlobalSize(Globals.EntryTable))!=HFILE_ERROR)
{
_lclose(hfRegistry);
}
_lclose(hfRegistry);
}
GlobalUnlock(Globals.EntryTable);
// save strings
lpRegistry=GlobalLock(Globals.StringTable);
if ((hfRegistry=_lcreat(szPath, 0))!=HFILE_ERROR)
{
if (_lwrite(hfRegistry, lpRegistry, GlobalSize(Globals.StringTable))!=HFILE_ERROR)
{
_lclose(hfRegistry);
}
_lclose(hfRegistry);
}
GlobalUnlock(Globals.StringTable);
}
return( 1 );
}

28 changes: 16 additions & 12 deletions dlls/shell/Shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@

/* Global Data */
typedef struct tagGLOBALS {
HINSTANCE hInstance;
HGLOBAL EntryTable;
HGLOBAL StringTable;
HINSTANCE hInstance; // SHELL.EXE Instance
HGLOBAL Registry; // Registry Header Handle
HGLOBAL EntryTable; // Registry Entries Table
HGLOBAL StringTable; // Registry String Table
} GLOBALS;

extern GLOBALS Globals;
Expand Down Expand Up @@ -89,7 +90,6 @@ int lstrnicmp(char FAR *s1, const char FAR *s2, int n);
char FAR *lstrchr(const char FAR *s, int c);
void lmemcpy(void FAR * s1, void FAR * s2, unsigned length);
void FAR * lmemset (void FAR *start, int c, int len);
//int toupper (int c);

#define GET_WM_COMMAND_ID(wp, lp) (wp)

Expand Down Expand Up @@ -423,13 +423,13 @@ extern KEYSTRUCT RootKey;

typedef struct tagDATHEADER {
char szSignature[8]; //0x0000 8 Byte ASCII-Text: "SHCC3.10"
DWORD unk1; //0x0008 D-Word ?
DWORD unk2; //0x000C D-Word ? (always equal the D-Word at 0x0008) Note: May be first is header size, second is offset of navblock
DWORD dwEntries; //0x0010 D-Word Number of entrys in the navigation-block
DWORD offsetDataBlock; //0x0014 D-Word Offset of the data-block
DWORD sizeDataBlock; //0x0018 D-Word Size of the data-block
WORD unk3; //0x001C Word ?
WORD unk4; //0x001E Word ?
DWORD unk1; //0x0008 DWord ?
DWORD unk2; //0x000C DWord ? (always equal the D-Word at 0x0008) Note: May be first is header size, second is offset of navblock
DWORD dwEntries; //0x0010 DWord Number of entries in the navigation-block
DWORD offsetDataBlock; //0x0014 DWord Offset of the data-block
DWORD sizeDataBlock; //0x0018 DWord Size of the data-block
WORD hashsize; //0x00?? Word Hash size
WORD freeidx; //0x00?? Word Free index
} DATHEADER;

typedef struct tagDATNAVIGATION {
Expand All @@ -440,7 +440,7 @@ typedef struct tagDATNAVIGATION {
} DATNAVIGATION;

typedef struct tagDATTEXT {
WORD unk1; //0x00 Word ?
WORD Index; //0x00 Word Entry Table Index * 2 + 1
WORD RefCount; //0x02 Word number of references to this text
WORD Length; //0x04 Word Text-length
WORD offset; //0x06 Word Offset of the text-string inside the data-block
Expand All @@ -465,4 +465,8 @@ Text-Info-Record
Offset Size Contents
*/

BOOL InitReg();
24 changes: 19 additions & 5 deletions dlls/shell/note.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ need to add new string to strings.
deduced from the reg.dat file by me. Mistakes may
have been made. I claim no rights and give no guarantees for this program.

Tor Sj?wall, [email protected]
Tor Sjoewall, [email protected]
*/


Expand Down Expand Up @@ -319,7 +319,7 @@ Initialization of REG.DAT
=========================

REG.DAT is initially created during DLL Initialization. Name of REG.DAT is taken from String reousrce 208.
Initial content of REG.DAT taken from Resource id=100(9999??). If REG.DAT doesn't exists, then it created from
Initial content of REG.DAT taken from Resource type=100 id=100. If REG.DAT doesn't exists, then it created from
resource.

Easter Eggs
Expand All @@ -331,15 +331,16 @@ It is animated Logo Flag and Bear, Gates and others.
Resourses
=========

SHELL.DLL contains some resources, used mostly for About Dialog. Interesting thing is
resource 9999 is a empty REG.DAT, used to create initial emoty Registry.
SHELL.DLL contains some resources, used mostly for About Dialog.

130 OS Logo Bitmap 64x64 16 colors
9997 OS Flag Bitmap 129x33 16 colors
9998 Easter Egg (Gates, other and Bear) Bitmap 171x75 16 colors
Dialogs:
100 About Doalog Standard About Dialog
200 Exe Find Dialog Dialog shown for associations if not exe found
300 Exe Directory location Locate EXE dialog
Strings:
208 REG.DAT
209 Real Mode
210 Real Mode (Large Frame EMS)
Expand All @@ -357,7 +358,20 @@ resource 9999 is a empty REG.DAT, used to create initial emoty Registry.
225 (not found)
226 Cannot load COMMDLG.DLL
227 \nSHELL.DLL: RegCloseKey called with no corresponding RegOpenKey
9999 ????

100 100 Empty REG.DAT
1 Version Information Resources



Undocumented exports
====================
104 Create REG.DAT file from 100 100 resource
105 Calls int 21h AH=19h (get default drive)
106 Calls int 21h AH=0Eh (set default drive)
107 Unknown variable
108 Writes registry to REG.DAT
109 Unknown
110 Unknown
117 Calls int 21h AH=3Bh (SetCurrentDirectory)
118 Calls int 21h AH=47H (GetCurrentDirectory)
2 changes: 1 addition & 1 deletion libs/mfc/samples/hello/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ srcfiles = $(p)hello$(e) &
#$(p)Debug$(e) &

# defines additional options for C compiler
ADD_COPT = -xs -i=..$(SEP)..$(SEP)Include -i=c:\watcom\h
ADD_COPT = -od -xs -i=..$(SEP)..$(SEP)Include -i=c:\watcom\h
ADD_LINKOPT = LIB commdlg.lib, ole2disp.lib

HEAPSIZE = 18k
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 0 additions & 23 deletions pal/modules/bp/Makefile

This file was deleted.

Loading

0 comments on commit 24c598a

Please sign in to comment.