ReactOS 0.4.15-dev-6669-g8227c5d
settings.c
Go to the documentation of this file.
1//
2// settings.c
3//
4// Load/Save settings from registry
5//
6#include <stdlib.h>
7#include <windows.h>
8#include <tchar.h>
9#include "globals.h"
10#include "message.h"
11#include "matrix.h"
12
16TCHAR g_szFontName[512] = _T("Arial");
17
19int g_nDensity = 32;
20int g_nFontSize = 12;
24
26
28{
29 HKEY hkey;
30 LONG value;
31 ULONG len;
32 TCHAR *hugechar = malloc(4096);
33 TCHAR *hptr = hugechar;
34
35 if(hugechar == 0)
36 return;
37
38 ZeroMemory(hugechar, 4096);
39
40 RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\Catch22\\Matrix Screen Saver"), 0,
41 _T(""), 0, KEY_READ, NULL, &hkey, NULL);
42
43 len = sizeof value;
44 if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("MessageSpeed"), 0, 0, (BYTE *)&value, &len))
45 {
48 }
49
50 if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("MatrixSpeed"), 0, 0, (BYTE *)&value, &len))
51 {
52 if(value >= SPEED_MIN && value <= SPEED_MAX)
54 }
55
56 if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("Density"), 0, 0, (BYTE *)&value, &len))
57 {
60 }
61
62 if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("FontSize"), 0, 0, (BYTE *)&value, &len))
63 {
64 if(value >= FONT_MIN && value <= FONT_MAX)
66 }
67
68 if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("FontBold"), 0, 0, (BYTE *)&value, &len))
69 g_fFontBold = (value == 0 ? FALSE : TRUE);
70
71 if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("Randomize"), 0, 0, (BYTE *)&value, &len))
73
74 len = 512;
75 if(RegQueryValueEx(hkey, _T("FontName"), 0, 0, (BYTE *)g_szFontName, &len) != ERROR_SUCCESS)
76 lstrcpy(g_szFontName, _T("Arial"));
77
78 len = 4096;
79
80 if(ERROR_SUCCESS == RegQueryValueEx(hkey, _T("Messages"), 0, 0 , (BYTE *)hugechar, &len))
81 {
82 while(len > 0 && *hptr && _istascii(*hptr))
83 {
84 if(lstrlen(hptr) > 0)
85 {
88 hptr += lstrlen(hptr) + 1;
89 }
90 }
91 }
92 else
93 {
94 /* built-in coded message for first run */
95 lstrcpyn(g_szMessages[0], _T("ReactOS"), MAXMSG_LENGTH);
97 }
98
99 RegCloseKey(hkey);
100 free(hugechar);
101}
102
104{
105 HKEY hkey;
106 TCHAR *hugechar = malloc(4096 * sizeof(TCHAR));
107 TCHAR *msgptr = hugechar;
108 int totallen = 0;
109 int i,len;
110 LONG value;
111
112 if(hugechar == 0)
113 return;
114
115 ZeroMemory(hugechar, 4096 * sizeof(TCHAR));
116 msgptr = hugechar;
117
118 RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\Catch22\\Matrix Screen Saver"), 0,
119 _T(""), 0, KEY_WRITE, NULL, &hkey, NULL);
120
122 RegSetValueEx(hkey, _T("MessageSpeed"), 0, REG_DWORD, (BYTE *)&value, sizeof value);
123
125 RegSetValueEx(hkey, _T("MatrixSpeed"), 0, REG_DWORD, (BYTE *)&value, sizeof value);
126
128 RegSetValueEx(hkey, _T("Density"), 0, REG_DWORD, (BYTE *)&value, sizeof value);
129
131 RegSetValueEx(hkey, _T("FontSize"), 0, REG_DWORD, (BYTE *)&value, sizeof value);
132
134 RegSetValueEx(hkey, _T("Randomize"), 0, REG_DWORD, (BYTE *)&value, sizeof value);
135
137 RegSetValueEx(hkey, _T("FontBold"), 0, REG_DWORD, (BYTE *)&value, sizeof value);
138
139 RegSetValueEx(hkey, _T("FontName"), 0, REG_SZ, (BYTE *)g_szFontName, lstrlen(g_szFontName) * sizeof(TCHAR));
140
141 for(i = 0; i < g_nNumMessages; i++)
142 {
144
145 if(len > 0 && totallen+len < 4096)
146 {
147 lstrcpyn(msgptr, g_szMessages[i], 4096-totallen);
148 totallen += len + 1;
149 msgptr += len + 1;
150 }
151 }
152
153 //*msgptr = _T('\0');
154 totallen++;
155
156 RegSetValueEx(hkey, _T("Messages"), 0, REG_MULTI_SZ, (BYTE *)hugechar, totallen * sizeof(TCHAR));
157 RegCloseKey(hkey);
158
159 free(hugechar);
160}
void SaveSettings(void)
Definition: settings.c:115
void LoadSettings(void)
Definition: settings.c:53
#define RegCloseKey(hKey)
Definition: registry.h:47
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _istascii
Definition: tchar.h:738
#define REG_SZ
Definition: layer.c:22
#define MAX_MESSAGES
Definition: globals.h:30
#define MAXMSG_LENGTH
Definition: globals.h:25
#define FONT_MAX
Definition: globals.h:33
#define DENSITY_MAX
Definition: globals.h:11
#define DENSITY_MIN
Definition: globals.h:12
#define FONT_MIN
Definition: globals.h:32
#define MSGSPEED_MIN
Definition: globals.h:28
#define SPEED_MAX
Definition: globals.h:20
#define SPEED_MIN
Definition: globals.h:21
#define MSGSPEED_MAX
Definition: globals.h:27
int g_nNumMessages
Definition: settings.c:14
BOOL g_fRandomizeMessages
Definition: settings.c:21
TCHAR g_szMessages[MAX_MESSAGES][MAXMSG_LENGTH]
Definition: settings.c:13
int g_nMatrixSpeed
Definition: settings.c:18
BOOL g_fFontBold
Definition: settings.c:22
BOOL g_fScreenSaving
Definition: settings.c:23
int g_nFontSize
Definition: settings.c:20
int g_nMessageSpeed
Definition: settings.c:15
TCHAR g_szFontName[512]
Definition: settings.c:16
int g_nDensity
Definition: settings.c:19
HFONT g_hFont
Definition: settings.c:25
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define KEY_READ
Definition: nt_native.h:1023
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define KEY_WRITE
Definition: nt_native.h:1031
long LONG
Definition: pedump.c:60
#define REG_DWORD
Definition: sdbapi.c:596
uint32_t ULONG
Definition: typedefs.h:59
Definition: pdh_main.c:94
#define _T(x)
Definition: vfdio.h:22
#define lstrcpyn
Definition: winbase.h:3800
#define ZeroMemory
Definition: winbase.h:1700
#define lstrcpy
Definition: winbase.h:3799
#define lstrlen
Definition: winbase.h:3801
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define RegQueryValueEx
Definition: winreg.h:524
char TCHAR
Definition: xmlstorage.h:189
unsigned char BYTE
Definition: xxhash.c:193