ReactOS  0.4.15-dev-1177-g6cb3b62
settings.cpp File Reference
#include "rapps.h"
#include "settings.h"
Include dependency graph for settings.cpp:

Go to the source code of this file.

Classes

class  SettingsField
 
class  SettingsFieldBool
 
class  SettingsFieldInt
 
class  SettingsFieldString
 

Functions

void AddInfoFields (ATL::CAtlList< SettingsField * > &infoFields, SETTINGS_INFO &settings)
 
BOOL SaveAllSettings (CRegKey &key, SETTINGS_INFO &settings)
 
BOOL LoadAllSettings (CRegKey &key, SETTINGS_INFO &settings)
 
VOID FillDefaultSettings (PSETTINGS_INFO pSettingsInfo)
 
BOOL LoadSettings (PSETTINGS_INFO pSettingsInfo)
 
BOOL SaveSettings (HWND hwnd, PSETTINGS_INFO pSettingsInfo)
 

Function Documentation

◆ AddInfoFields()

void AddInfoFields ( ATL::CAtlList< SettingsField * > &  infoFields,
SETTINGS_INFO settings 
)

Definition at line 104 of file settings.cpp.

105 {
106  infoFields.AddTail(new SettingsFieldBool(&(settings.bSaveWndPos), L"bSaveWndPos"));
107  infoFields.AddTail(new SettingsFieldBool(&(settings.bUpdateAtStart), L"bUpdateAtStart"));
108  infoFields.AddTail(new SettingsFieldBool(&(settings.bLogEnabled), L"bLogEnabled"));
109  infoFields.AddTail(new SettingsFieldString(settings.szDownloadDir, MAX_PATH, L"szDownloadDir"));
110  infoFields.AddTail(new SettingsFieldBool(&(settings.bDelInstaller), L"bDelInstaller"));
111  infoFields.AddTail(new SettingsFieldBool(&(settings.Maximized), L"WindowPosMaximized"));
112  infoFields.AddTail(new SettingsFieldInt(&(settings.Left), L"WindowPosLeft"));
113  infoFields.AddTail(new SettingsFieldInt(&(settings.Top), L"WindowPosTop"));
114  infoFields.AddTail(new SettingsFieldInt(&(settings.Width), L"WindowPosWidth"));
115  infoFields.AddTail(new SettingsFieldInt(&(settings.Height), L"WindowPosHeight"));
116  infoFields.AddTail(new SettingsFieldInt(&(settings.Proxy), L"ProxyMode"));
117  infoFields.AddTail(new SettingsFieldString((settings.szProxyServer), MAX_PATH, L"ProxyServer"));
118  infoFields.AddTail(new SettingsFieldString((settings.szNoProxyFor), MAX_PATH, L"NoProxyFor"));
119  infoFields.AddTail(new SettingsFieldBool(&(settings.bUseSource), L"bUseSource"));
120  infoFields.AddTail(new SettingsFieldString((settings.szSourceURL), INTERNET_MAX_URL_LENGTH, L"SourceURL"));
121 
122  return;
123 }
struct mke2fs_defaults settings[]
#define INTERNET_MAX_URL_LENGTH
Definition: session.c:1418
#define MAX_PATH
Definition: compat.h:34
static const WCHAR L[]
Definition: oid.c:1250
POSITION AddTail(INARGTYPE element)
Definition: atlcoll.h:624

Referenced by LoadAllSettings(), and SaveAllSettings().

◆ FillDefaultSettings()

VOID FillDefaultSettings ( PSETTINGS_INFO  pSettingsInfo)

Definition at line 167 of file settings.cpp.

168 {
169  ATL::CStringW szDownloadDir;
170  ZeroMemory(pSettingsInfo, sizeof(SETTINGS_INFO));
171 
172  pSettingsInfo->bSaveWndPos = TRUE;
173  pSettingsInfo->bUpdateAtStart = FALSE;
174  pSettingsInfo->bLogEnabled = TRUE;
175  pSettingsInfo->bUseSource = FALSE;
176 
178  {
179  szDownloadDir.ReleaseBuffer();
180  if (!szDownloadDir.GetEnvironmentVariableW(L"SystemDrive"))
181  {
182  szDownloadDir = L"C:";
183  }
184  }
185  else
186  {
187  szDownloadDir.ReleaseBuffer();
188  }
189 
190  PathAppendW(szDownloadDir.GetBuffer(MAX_PATH), L"\\RAPPS Downloads");
191  szDownloadDir.ReleaseBuffer();
192 
194  _countof(pSettingsInfo->szDownloadDir),
195  szDownloadDir.GetString(),
196  szDownloadDir.GetLength() + 1);
197 
198  pSettingsInfo->bDelInstaller = FALSE;
199  pSettingsInfo->Maximized = FALSE;
200  pSettingsInfo->Left = CW_USEDEFAULT;
201  pSettingsInfo->Top = CW_USEDEFAULT;
202  pSettingsInfo->Width = 680;
203  pSettingsInfo->Height = 450;
204 }
int GetLength() const
Definition: atlsimpstr.h:356
BOOL bUpdateAtStart
Definition: settings.h:8
#define TRUE
Definition: types.h:120
#define ZeroMemory
Definition: winbase.h:1648
BOOL Maximized
Definition: settings.h:13
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:121
WCHAR szDownloadDir[MAX_PATH]
Definition: settings.h:10
BOOL bUseSource
Definition: settings.h:23
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
#define FALSE
Definition: types.h:117
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
PCXSTR GetString() const
Definition: atlsimpstr.h:361
static const WCHAR L[]
Definition: oid.c:1250
BOOL bLogEnabled
Definition: settings.h:9
static void __cdecl CopyChars(_Out_writes_to_(nDestLen, nChars) XCHAR *pchDest, _In_ size_t nDestLen, _In_reads_opt_(nChars) const XCHAR *pchSrc, _In_ int nChars)
Definition: atlsimpstr.h:423
BOOL bDelInstaller
Definition: settings.h:11
#define CSIDL_PERSONAL
Definition: shlobj.h:2017
HRESULT WINAPI SHGetFolderPathW(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath)
Definition: shellpath.c:2208
BOOL bSaveWndPos
Definition: settings.h:7

Referenced by anonymous_namespace{settingsdlg.cpp}::SettingsDlgProc(), and wmain().

◆ LoadAllSettings()

BOOL LoadAllSettings ( CRegKey key,
SETTINGS_INFO settings 
)

Definition at line 146 of file settings.cpp.

147 {
148  BOOL bAllSuccess = TRUE;
150 
151  AddInfoFields(infoFields, settings);
152 
153  POSITION InfoListPosition = infoFields.GetHeadPosition();
154  while (InfoListPosition)
155  {
156  SettingsField *Info = infoFields.GetNext(InfoListPosition);
157  if (!Info->Load(key))
158  {
159  bAllSuccess = FALSE;
160  // TODO: error log
161  }
162  delete Info;
163  }
164  return bAllSuccess;
165 }
struct mke2fs_defaults settings[]
POSITION GetHeadPosition() const
Definition: atlcoll.h:549
#define TRUE
Definition: types.h:120
void AddInfoFields(ATL::CAtlList< SettingsField * > &infoFields, SETTINGS_INFO &settings)
Definition: settings.cpp:104
struct TraceInfo Info
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
E & GetNext(_Inout_ POSITION &pos)
Definition: atlcoll.h:561
Definition: path.c:41

Referenced by LoadSettings().

◆ LoadSettings()

BOOL LoadSettings ( PSETTINGS_INFO  pSettingsInfo)

Definition at line 206 of file settings.cpp.

207 {
208  ATL::CRegKey RegKey;
209  if (RegKey.Open(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", KEY_READ) != ERROR_SUCCESS)
210  {
211  return FALSE;
212  }
213 
214  return LoadAllSettings(RegKey, *pSettingsInfo);
215 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define FALSE
Definition: types.h:117
LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName, REGSAM samDesired=KEY_READ|KEY_WRITE)
Definition: atlbase.h:1070
BOOL LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings)
Definition: settings.cpp:146
static const WCHAR L[]
Definition: oid.c:1250

◆ SaveAllSettings()

BOOL SaveAllSettings ( CRegKey key,
SETTINGS_INFO settings 
)

Definition at line 125 of file settings.cpp.

126 {
127  BOOL bAllSuccess = TRUE;
129 
130  AddInfoFields(infoFields, settings);
131 
132  POSITION InfoListPosition = infoFields.GetHeadPosition();
133  while (InfoListPosition)
134  {
135  SettingsField *Info = infoFields.GetNext(InfoListPosition);
136  if (!Info->Save(key))
137  {
138  bAllSuccess = FALSE;
139  // TODO: error log
140  }
141  delete Info;
142  }
143  return bAllSuccess;
144 }
struct mke2fs_defaults settings[]
POSITION GetHeadPosition() const
Definition: atlcoll.h:549
#define TRUE
Definition: types.h:120
void AddInfoFields(ATL::CAtlList< SettingsField * > &infoFields, SETTINGS_INFO &settings)
Definition: settings.cpp:104
struct TraceInfo Info
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
E & GetNext(_Inout_ POSITION &pos)
Definition: atlcoll.h:561
Definition: path.c:41

Referenced by SaveSettings().

◆ SaveSettings()

BOOL SaveSettings ( HWND  hwnd,
PSETTINGS_INFO  pSettingsInfo 
)

Definition at line 217 of file settings.cpp.

218 {
219  WINDOWPLACEMENT wp;
220  ATL::CRegKey RegKey;
221 
222  if (pSettingsInfo->bSaveWndPos)
223  {
224  wp.length = sizeof(wp);
225  GetWindowPlacement(hwnd, &wp);
226 
227  pSettingsInfo->Left = wp.rcNormalPosition.left;
228  pSettingsInfo->Top = wp.rcNormalPosition.top;
229  pSettingsInfo->Width = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
230  pSettingsInfo->Height = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
231  pSettingsInfo->Maximized = (wp.showCmd == SW_MAXIMIZE
232  || (wp.showCmd == SW_SHOWMINIMIZED
233  && (wp.flags & WPF_RESTORETOMAXIMIZED)));
234  }
235 
236  if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL,
238  {
239  return FALSE;
240  }
241 
242  return SaveAllSettings(RegKey, *pSettingsInfo);
243 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HKEY_CURRENT_USER
Definition: winreg.h:11
BOOL SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings)
Definition: settings.cpp:125
LONG top
Definition: windef.h:307
#define WPF_RESTORETOMAXIMIZED
Definition: winuser.h:2507
LONG left
Definition: windef.h:306
#define SW_SHOWMINIMIZED
Definition: winuser.h:765
LONG right
Definition: windef.h:308
BOOL Maximized
Definition: settings.h:13
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
static const WCHAR L[]
Definition: oid.c:1250
LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass=REG_NONE, DWORD dwOptions=REG_OPTION_NON_VOLATILE, REGSAM samDesired=KEY_READ|KEY_WRITE, LPSECURITY_ATTRIBUTES lpSecAttr=NULL, LPDWORD lpdwDisposition=NULL)
Definition: atlbase.h:1091
RECT rcNormalPosition
Definition: winuser.h:3270
BOOL bSaveWndPos
Definition: settings.h:7
LONG bottom
Definition: windef.h:309
#define SW_MAXIMIZE
Definition: winuser.h:766