00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "stdafx.h"
00032 #include "regwrap.h"
00033
00034 RegWrap::RegWrap(void)
00035 {
00036 }
00037
00038 RegWrap::~RegWrap(void)
00039 {
00040 }
00041
00042 LONG RegWrap::addKeyVal(HKEY inHive, string inKeyName, string inValueName, string inValue) {
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 HKEY locKey;
00073 DWORD locDisp;
00074 LONG retVal = RegCreateKeyEx( inHive,
00075 inKeyName.c_str(),
00076 NULL,
00077 NULL,
00078 REG_OPTION_NON_VOLATILE,
00079 KEY_ALL_ACCESS,
00080 NULL,
00081 &locKey,
00082 &locDisp);
00083
00084 if (retVal != ERROR_SUCCESS) {
00085
00086 return retVal;
00087 }
00088
00089 retVal = RegSetValueEx( locKey,
00090 inValueName.c_str(),
00091 NULL,
00092 REG_SZ,
00093 (const BYTE*)inValue.c_str(),
00094 (DWORD)(inValue.length()+1));
00095
00096 if (retVal != ERROR_SUCCESS) {
00097
00098 return retVal;
00099 }
00100
00101 RegCloseKey(locKey);
00102
00103
00104 return retVal;
00105
00106 }
00107
00108 bool RegWrap::deleteKeyRecurse(HKEY inHive, string inKeyName, string inSubKeyToDelete) {
00109 HKEY locKey;
00110 LONG retVal;
00111
00112 retVal = RegOpenKeyEx( inHive,
00113 inKeyName.c_str(),
00114 NULL,
00115 KEY_ALL_ACCESS,
00116 &locKey);
00117
00118 if (retVal != ERROR_SUCCESS) {
00119
00120 return false;
00121 }
00122
00123 retVal = SHDeleteKeyA(locKey, inSubKeyToDelete.c_str());
00124 RegCloseKey(locKey);
00125 return true;
00126
00127 }
00128
00129
00130
00131 bool RegWrap::removeKeyVal(HKEY inHive, string inKeyName, string inValueName) {
00132
00133
00134
00135
00136
00137 HKEY locKey;
00138 LONG retVal;
00139
00140 retVal = RegOpenKeyEx( inHive,
00141 inKeyName.c_str(),
00142 NULL,
00143 KEY_ALL_ACCESS,
00144 &locKey);
00145
00146 if (retVal != ERROR_SUCCESS) {
00147
00148 return false;
00149 }
00150
00151 retVal = RegDeleteValue(locKey, inValueName.c_str());
00152 RegCloseKey(locKey);
00153 if (retVal != ERROR_SUCCESS) {
00154 return false;
00155 } else {
00156 return true;
00157 }
00158 }
00159
00160 bool RegWrap::valueExists(HKEY inHive, string inKeyName, string inValueName) {
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182 HKEY locKey;
00183 LONG retVal;
00184
00185
00186 retVal = RegOpenKeyEx( inHive,
00187 inKeyName.c_str(),
00188 NULL,
00189 KEY_ALL_ACCESS,
00190 &locKey);
00191
00192 if (retVal != ERROR_SUCCESS) {
00193
00194 return false;
00195 }
00196
00197 retVal = RegQueryValueEx( locKey,
00198 inValueName.c_str(),
00199 NULL,
00200 NULL,
00201 NULL,
00202 NULL);
00203
00204 RegCloseKey(locKey);
00205 if (retVal != ERROR_SUCCESS) {
00206
00207 return false;
00208 } else {
00209
00210 return true;
00211 }
00212
00213 }
00214
00215 string RegWrap::findNextEmptyMediaPlayerDesc() {
00216 char locNum[6];
00217 string foundNum = "";
00218 for (long i = 1; i < 24; i++) {
00219 itoa(i, (char*)&locNum, 10);
00220 if (!RegWrap::valueExists(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\Descriptions", (char*)&locNum)) {
00221 foundNum = (char*)&locNum;
00222 break;
00223 }
00224
00225 }
00226 return foundNum;
00227 }
00228
00229 bool RegWrap::removeMediaDesc() {
00230 HKEY locKey;
00231 LONG retVal;
00232
00233 retVal = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
00234 "SOFTWARE\\illiminable\\oggcodecs",
00235 NULL,
00236 KEY_ALL_ACCESS,
00237 &locKey);
00238
00239 if (retVal != ERROR_SUCCESS) {
00240
00241 return false;
00242 }
00243
00244 DWORD locBuffSize = 16;
00245 char locBuff[16];
00246
00247 retVal = RegQueryValueEx( locKey,
00248 "MediaDescNum",
00249 NULL,
00250 NULL,
00251 (BYTE*)&locBuff,
00252 &locBuffSize);
00253
00254 RegCloseKey(locKey);
00255 if (retVal != ERROR_SUCCESS) {
00256
00257 return false;
00258 } else {
00259 RegWrap::removeKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\Descriptions", locBuff);
00260 RegWrap::removeKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\MUIDescriptions", locBuff);
00261 RegWrap::removeKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\Types", locBuff);
00262 RegWrap::removeKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\illiminable\\oggcodecs", "MediaDescNum");
00263
00264 return true;
00265
00266 }
00267
00268
00269 }
00270 bool RegWrap::addMediaPlayerDesc(string inDesc, string inExts) {
00271 if (!RegWrap::valueExists(HKEY_LOCAL_MACHINE, "SOFTWARE\\illiminable\\oggcodecs", "MediaDescNum")) {
00272 string locDescNum = "";
00273 string locFull = inDesc+" ("+inExts+")";
00274 locDescNum = RegWrap::findNextEmptyMediaPlayerDesc();
00275 if (locDescNum == "") {
00276 return false;
00277 }
00278 RegWrap::addKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\illiminable\\oggcodecs", "MediaDescNum", locDescNum.c_str());
00279 RegWrap::addKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\Descriptions", locDescNum, locFull.c_str());
00280 RegWrap::addKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\MUIDescriptions", locDescNum, inDesc.c_str());
00281 RegWrap::addKeyVal(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\MediaPlayer\\Player\\Extensions\\Types", locDescNum, inExts.c_str());
00282 return true;
00283 }
00284
00285 }