Registry
Overview
The Registry provides Windows-compatible registry functionality for FreeWorld OS. It manages registry hives (HKLM, HKCU, HKCR, etc.), keys, values, and provides transaction support, import/export, and automatic persistence.
Features
- Hive Management: Complete support for all standard Windows registry hives
- Key/Value Operations: Create, read, update, delete keys and values
- Transaction Support: Begin, commit, and rollback registry transactions
- Import/Export: Save and load registry hives to/from disk
- Auto-Load: Automatic persistence on startup
- Value Types: Support for REG_SZ, REG_DWORD, REG_QWORD, REG_BINARY, REG_MULTI_SZ
- Key Enumeration: List subkeys and values
Registry Hives
The Registry supports all standard Windows registry hives:
- HKEY_LOCAL_MACHINE (HKLM): System-wide configuration
- HKEY_CURRENT_USER (HKCU): User-specific configuration
- HKEY_CLASSES_ROOT (HKCR): File associations and COM classes
- HKEY_USERS (HKU): All user profiles
- HKEY_CURRENT_CONFIG (HKCC): Current hardware configuration
Key Operations
openKey(hKey, subKey, access)- Open a registry keycreateKeyPath(hKey, subKey)- Create a registry key pathdeleteKey(hKey, subKey)- Delete a registry keyenumerateKeys(hKey, subKey)- List all subkeyskeyExists(hKey, subKey)- Check if key existsgetKeyInfo(hKey, subKey)- Get key information
Value Operations
setValue(hKey, subKey, valueName, value, type)- Set a registry valuequeryValue(hKey, subKey, valueName)- Query a registry valuequeryValues(hKey, subKey)- Query all values in a keydeleteValue(hKey, subKey, valueName)- Delete a registry valueenumerateValues(hKey, subKey)- List all valuesvalueExists(hKey, subKey, valueName)- Check if value exists
Value Types
The Registry supports the following value types:
- REG_SZ: String value
- REG_DWORD: 32-bit integer
- REG_QWORD: 64-bit integer
- REG_BINARY: Binary data
- REG_MULTI_SZ: Multiple strings
Transactions
The Registry supports transactions for atomic operations:
beginTransaction()- Begin a transaction (creates snapshot)commitTransaction(transaction)- Commit transaction (saves to disk)rollbackTransaction(transaction)- Rollback transaction (restore from snapshot)
Persistence
The Registry automatically saves and loads hives from disk:
flush()- Save all hives to disksaveHiveToDisk(hiveName, filePath)- Save single hive to diskloadHiveFromDisk(hiveName, filePath)- Load single hive from diskexportKey(hKey, subKey, filePath)- Export key to fileimportKey(hKey, subKey, filePath)- Import key from fileautoLoad()- Automatically load all hives on startup
Registry data is stored in JSON format in the registry/ directory.
Usage Example
const Registry = require('./system/registry');
const registry = new Registry();
// Set a value
registry.setValue('HKEY_LOCAL_MACHINE', 'SOFTWARE\\FreeWorld', 'Version', '1.0.0', 'REG_SZ');
// Query a value
const version = registry.queryValue('HKEY_LOCAL_MACHINE', 'SOFTWARE\\FreeWorld', 'Version');
console.log(version.data); // '1.0.0'
// Create a key
registry.createKeyPath('HKEY_CURRENT_USER', 'Software\\MyApp');
// Set multiple values
registry.setValue('HKEY_CURRENT_USER', 'Software\\MyApp', 'Setting1', 'value1', 'REG_SZ');
registry.setValue('HKEY_CURRENT_USER', 'Software\\MyApp', 'Setting2', 42, 'REG_DWORD');
// Enumerate values
const values = registry.enumerateValues('HKEY_CURRENT_USER', 'Software\\MyApp');
// Returns: ['Setting1', 'Setting2']
// Flush to disk
registry.flush();
Integration
The Registry integrates with:
- ShellExecute: Used for file association management
- System Configuration: Stores system-wide settings
- Application Settings: Stores application-specific settings
- File Associations: Manages file type associations