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
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
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
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
00068 return retVal;
00069 }
00070
00071 RegCloseKey(locKey);
00072
00073
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
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
00103
00104
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
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
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 HKEY locKey;
00153 LONG retVal;
00154
00155
00156 retVal = RegOpenKeyEx( inHive,
00157 inKeyName.c_str(),
00158 NULL,
00159 KEY_ALL_ACCESS,
00160 &locKey);
00161
00162 if (retVal != ERROR_SUCCESS) {
00163
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
00177 return false;
00178 } else {
00179
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
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
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
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 }