RegWrap.cpp

Go to the documentation of this file.
00001 #include "stdafx.h"
00002 #include "regwrap.h"
00003 
00004 RegWrap::RegWrap(void)
00005 {
00006 }
00007 
00008 RegWrap::~RegWrap(void)
00009 {
00010 }
00011 
00012 LONG RegWrap::addKeyVal(HKEY inHive, string inKeyName, string inValueName, string inValue) {
00013         //Open or create keyname
00014         //Add a value called ValueName with value inValue.
00015 
00016         //LONG RegCreateKeyEx(
00017         //      HKEY hKey,
00018         //      LPCTSTR lpSubKey,
00019         //      DWORD Reserved,
00020         //      LPTSTR lpClass,
00021         //      DWORD dwOptions,
00022         //      REGSAM samDesired,
00023         //      LPSECURITY_ATTRIBUTES lpSecurityAttributes,
00024         //      PHKEY phkResult,
00025         //      LPDWORD lpdwDisposition
00026         //);
00027 
00028 
00029         //LONG RegSetValueEx(
00030         //      HKEY hKey,
00031         //      LPCTSTR lpValueName,
00032         //      DWORD Reserved,
00033         //      DWORD dwType,
00034         //      const BYTE* lpData,
00035         //      DWORD cbData
00036         //);
00037 
00038 
00039         //fstream debugLog;
00040         //debugLog.open("G:\\reg.log", ios_base::out);
00041         //debugLog <<"Key = "<<inKeyName<<endl<<"ValueName = "<<inValueName<<endl<<"Value = "<<inValue<<endl;
00042         HKEY locKey;
00043         DWORD locDisp;
00044         LONG retVal = RegCreateKeyEx(   inHive,
00045                                                                         inKeyName.c_str(),
00046                                                                         NULL,
00047                                                                         NULL,
00048                                                                         REG_OPTION_NON_VOLATILE,
00049                                                                         KEY_ALL_ACCESS,
00050                                                                         NULL,
00051                                                                         &locKey,
00052                                                                         &locDisp);
00053 
00054         if (retVal != ERROR_SUCCESS) {
00055                 //debugLog<<"Create Failed"<<endl;
00056                 return retVal;
00057         }
00058 
00059         retVal = RegSetValueEx(         locKey,
00060                                                                 inValueName.c_str(),
00061                                                                 NULL,
00062                                                                 REG_SZ,
00063                                                                 (const BYTE*)inValue.c_str(),
00064                                                                 (DWORD)(inValue.length()+1));
00065 
00066         if (retVal != ERROR_SUCCESS) {
00067                 //debugLog<<"Set Value Failed"<<endl;
00068                 return retVal;
00069         }
00070         
00071         RegCloseKey(locKey);
00072 
00073         //debugLog.close();
00074         return retVal;
00075 
00076 }
00077 
00078 bool RegWrap::deleteKeyRecurse(HKEY inHive, string inKeyName, string inSubKeyToDelete) {
00079         HKEY locKey;
00080         LONG retVal;
00081 
00082         retVal = RegOpenKeyEx(  inHive,
00083                                                         inKeyName.c_str(),
00084                                                         NULL,
00085                                                         KEY_ALL_ACCESS,
00086                                                         &locKey);
00087 
00088         if (retVal != ERROR_SUCCESS) {
00089                 //debugLog<<"Key not found"<<endl;
00090                 return false;
00091         }
00092 
00093         retVal = SHDeleteKeyA(locKey, inSubKeyToDelete.c_str());
00094         RegCloseKey(locKey);
00095         return true;
00096 
00097 }
00098 
00099 
00100 
00101 bool RegWrap::removeKeyVal(HKEY inHive, string inKeyName, string inValueName) {
00102         //LONG RegDeleteValue(
00103         //      HKEY hKey,
00104         //      LPCTSTR lpValueName
00105         //);
00106 
00107         HKEY locKey;
00108         LONG retVal;
00109 
00110         retVal = RegOpenKeyEx(  inHive,
00111                                                         inKeyName.c_str(),
00112                                                         NULL,
00113                                                         KEY_ALL_ACCESS,
00114                                                         &locKey);
00115 
00116         if (retVal != ERROR_SUCCESS) {
00117                 //debugLog<<"Key not found"<<endl;
00118                 return false;
00119         }
00120 
00121         retVal = RegDeleteValue(locKey, inValueName.c_str());
00122         RegCloseKey(locKey);
00123         if (retVal != ERROR_SUCCESS) {
00124                 return false;
00125         } else {
00126                 return true;
00127         }
00128 }
00129 
00130 bool RegWrap::valueExists(HKEY inHive, string inKeyName, string inValueName) {
00131 
00132         //LONG RegQueryValueEx(
00133         //      HKEY hKey,
00134         //      LPCTSTR lpValueName,
00135         //      LPDWORD lpReserved,
00136         //      LPDWORD lpType,
00137         //      LPBYTE lpData,
00138         //      LPDWORD lpcbData
00139         //);
00140 
00141         //LONG RegOpenKeyEx(
00142         //      HKEY hKey,
00143         //      LPCTSTR lpSubKey,
00144         //      DWORD ulOptions,
00145         //      REGSAM samDesired,
00146         //      PHKEY phkResult
00147         //);
00148 
00149         //fstream debugLog;
00150         //HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MediaPlayer\Player\Extensions\Descriptions
00151         //debugLog.open("G:\\val.log", ios_base::out);
00152         HKEY locKey;
00153         LONG retVal;
00154         //debugLog<<"Querying : Key = "<<inKeyName<<endl<<"Value = "<<inValueName<<endl;
00155 
00156         retVal = RegOpenKeyEx(  inHive,
00157                                                         inKeyName.c_str(),
00158                                                         NULL,
00159                                                         KEY_ALL_ACCESS,
00160                                                         &locKey);
00161 
00162         if (retVal != ERROR_SUCCESS) {
00163                 //debugLog<<"Key not found"<<endl;
00164                 return false;
00165         }
00166 
00167         retVal = RegQueryValueEx(       locKey,
00168                                                                 inValueName.c_str(),
00169                                                                 NULL,
00170                                                                 NULL,
00171                                                                 NULL,
00172                                                                 NULL);
00173 
00174         RegCloseKey(locKey);
00175         if (retVal != ERROR_SUCCESS) {
00176                 //debugLog<<"Value not found"<<endl;
00177                 return false;
00178         } else {
00179                 //debugLog<<"Value found"<<endl;
00180                 return true;
00181         }
00182 
00183 }
00184 
00185 string RegWrap::findNextEmptyMediaPlayerDesc() {
00186         char locNum[6];
00187         string foundNum = "";
00188         for (long i = 1; i < 24; i++) {
00189                 itoa(i, (char*)&locNum, 10);
00190                 if (!RegWrap::valueExists(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\Descriptions", (char*)&locNum)) {
00191                         foundNum = (char*)&locNum;
00192                         break;
00193                 }
00194 
00195         }
00196         return foundNum;
00197 }
00198 
00199 bool RegWrap::removeMediaDesc() {
00200         HKEY locKey;
00201         LONG retVal;
00202 
00203         retVal = RegOpenKeyEx(  HKEY_LOCAL_MACHINE,
00204                                                         "SOFTWARE\\illiminable\\oggcodecs",
00205                                                         NULL,
00206                                                         KEY_ALL_ACCESS,
00207                                                         &locKey);
00208 
00209         if (retVal != ERROR_SUCCESS) {
00210                 //debugLog<<"Key not found"<<endl;
00211                 return false;
00212         }
00213 
00214         DWORD locBuffSize = 16;
00215         char locBuff[16];
00216 
00217         retVal = RegQueryValueEx(       locKey,
00218                                                                 "MediaDescNum",
00219                                                                 NULL,
00220                                                                 NULL,
00221                                                                 (BYTE*)&locBuff,
00222                                                                 &locBuffSize);
00223 
00224         RegCloseKey(locKey);
00225         if (retVal != ERROR_SUCCESS) {
00226                 //debugLog<<"Value not found"<<endl;
00227                 return false;
00228         } else {
00229                 RegWrap::removeKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\Descriptions", locBuff);
00230                 RegWrap::removeKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\MUIDescriptions", locBuff);
00231                 RegWrap::removeKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\Types", locBuff);
00232                 RegWrap::removeKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\illiminable\\oggcodecs", "MediaDescNum");
00233                 //debugLog<<"Value found"<<endl;
00234                 return true;
00235                 
00236         }
00237 
00238 
00239 }
00240 bool RegWrap::addMediaPlayerDesc(string inDesc, string inExts) {
00241         if (!RegWrap::valueExists(HKEY_LOCAL_MACHINE, "SOFTWARE\\illiminable\\oggcodecs", "MediaDescNum")) {
00242                 string locDescNum = "";
00243                 string locFull = inDesc+" ("+inExts+")";
00244                 locDescNum = RegWrap::findNextEmptyMediaPlayerDesc();
00245                 if (locDescNum == "") {
00246                         return false;
00247                 }
00248                 RegWrap::addKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\illiminable\\oggcodecs", "MediaDescNum", locDescNum.c_str());
00249                 RegWrap::addKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\Descriptions", locDescNum, locFull.c_str());
00250                 RegWrap::addKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\MUIDescriptions", locDescNum, inDesc.c_str());
00251                 RegWrap::addKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\Types", locDescNum, inExts.c_str());
00252                 return true;
00253         }
00254 
00255 }

Generated on Tue Feb 15 14:54:19 2005 for oggdsf by  doxygen 1.3.9