Back to index

lightning-sunbird  0.9+nobinonly
profilew.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include <windows.h>
00039 
00040 #include "profilew.h"
00041 
00042 ProfileWin::ProfileWin() : Profile()
00043 {
00044   hKey = NULL;
00045   char szClass[] = "SpyPluginClass";
00046   DWORD disp = 0L;
00047 
00048   LONG res = RegCreateKeyEx(HKEY_LOCAL_MACHINE, 
00049                             NPSPY_REG_SUBKEY, 
00050                             0L, 
00051                             szClass, 
00052                             0L, 
00053                             KEY_READ | KEY_WRITE, 
00054                             NULL, 
00055                             &hKey, 
00056                             &disp);
00057 
00058   if(res != ERROR_SUCCESS)
00059     hKey = NULL;
00060 }
00061 
00062 ProfileWin::~ProfileWin()
00063 {
00064   if(hKey)
00065     RegCloseKey(hKey);
00066 }
00067 
00068 BOOL ProfileWin::getBool(char * key, BOOL * value)
00069 {
00070   if(!value)
00071     return FALSE;
00072 
00073   DWORD size = sizeof(DWORD);
00074   DWORD val = 1L;
00075   LONG res = RegQueryValueEx(hKey, key, 0L, NULL, (BYTE *)&val, &size);
00076 
00077   if(res != ERROR_SUCCESS)
00078     return FALSE;
00079 
00080   *value = (val == 0L) ? FALSE : TRUE;
00081 
00082   return TRUE;
00083 }
00084 
00085 BOOL ProfileWin::setBool(char * key, BOOL value)
00086 {
00087   DWORD size = sizeof(DWORD);
00088   DWORD val = value ? 1L : 0L;
00089   LONG res = RegSetValueEx(hKey, key, 0L, REG_DWORD, (const BYTE *)&val, size);
00090   return (res == ERROR_SUCCESS);
00091 }
00092 
00093 BOOL ProfileWin::getString(char * key, char * string, int size)
00094 {
00095   LONG res = RegQueryValueEx(hKey, key, 0L, NULL, (BYTE *)string, (DWORD *)&size);
00096   return (res == ERROR_SUCCESS);
00097 }
00098 
00099 BOOL ProfileWin::setString(char * key, char * string)
00100 {
00101   DWORD size = strlen(string);
00102   LONG res = RegSetValueEx(hKey, key, 0L, REG_SZ, (const BYTE *)string, size);
00103   return (res == ERROR_SUCCESS);
00104 }
00105 
00106 BOOL ProfileWin::getSizeAndPosition(int *width, int *height, int *x, int *y)
00107 {
00108   DWORD size = sizeof(DWORD);
00109   LONG res = ERROR_SUCCESS;
00110 
00111   res = RegQueryValueEx(hKey, NPSPY_REG_KEY_WIDTH, 0L, NULL, (BYTE *)width, &size);
00112   if(res != ERROR_SUCCESS)
00113     return FALSE; 
00114 
00115   res = RegQueryValueEx(hKey, NPSPY_REG_KEY_HEIGHT, 0L, NULL, (BYTE *)height, &size);
00116   if(res != ERROR_SUCCESS)
00117     return FALSE; 
00118 
00119   res = RegQueryValueEx(hKey, NPSPY_REG_KEY_X, 0L, NULL, (BYTE *)x, &size);
00120   if(res != ERROR_SUCCESS)
00121     return FALSE; 
00122 
00123   res = RegQueryValueEx(hKey, NPSPY_REG_KEY_Y, 0L, NULL, (BYTE *)y, &size);
00124   if(res != ERROR_SUCCESS)
00125     return FALSE; 
00126 
00127   return TRUE;
00128 }
00129 
00130 BOOL ProfileWin::setSizeAndPosition(int width, int height, int x, int y)
00131 {
00132   DWORD size = sizeof(DWORD);
00133   LONG res = ERROR_SUCCESS;
00134   
00135   res = RegSetValueEx(hKey, NPSPY_REG_KEY_WIDTH, 0L, REG_DWORD, (const BYTE *)&width, size);
00136   if(res != ERROR_SUCCESS)
00137     return FALSE;
00138   
00139   res = RegSetValueEx(hKey, NPSPY_REG_KEY_HEIGHT, 0L, REG_DWORD, (const BYTE *)&height, size);
00140   if(res != ERROR_SUCCESS)
00141     return FALSE;
00142   
00143   res = RegSetValueEx(hKey, NPSPY_REG_KEY_X, 0L, REG_DWORD, (const BYTE *)&x, size);
00144   if(res != ERROR_SUCCESS)
00145     return FALSE;
00146   
00147   res = RegSetValueEx(hKey, NPSPY_REG_KEY_Y, 0L, REG_DWORD, (const BYTE *)&y, size);
00148   if(res != ERROR_SUCCESS)
00149     return FALSE;
00150 
00151   return TRUE;
00152 }