ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

regsvr.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2009 Vincent Povirk for CodeWeavers
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #define NONAMELESSUNION
00020 #define NONAMELESSSTRUCT
00021 #define COBJMACROS
00022 #include <stdarg.h>
00023 #include <string.h>
00024 
00025 #include "windef.h"
00026 #include "winbase.h"
00027 #include "wingdi.h"
00028 #include "winuser.h"
00029 #include "winreg.h"
00030 #include "winerror.h"
00031 
00032 #include "objbase.h"
00033 #include "ocidl.h"
00034 #include "wincodec.h"
00035 
00036 #include "wine/debug.h"
00037 #include "wine/unicode.h"
00038 
00039 WINE_DEFAULT_DEBUG_CHANNEL(wincodecs);
00040 
00041 /***********************************************************************
00042  *      interface for self-registering
00043  */
00044 struct regsvr_coclass
00045 {
00046     CLSID const *clsid;     /* NULL for end of list */
00047     LPCSTR name;        /* can be NULL to omit */
00048     LPCSTR ips;         /* can be NULL to omit */
00049     LPCSTR ips32;       /* can be NULL to omit */
00050     LPCSTR ips32_tmodel;    /* can be NULL to omit */
00051     LPCSTR progid;      /* can be NULL to omit */
00052     LPCSTR viprogid;        /* can be NULL to omit */
00053     LPCSTR progid_extra;    /* can be NULL to omit */
00054 };
00055 
00056 static HRESULT register_coclasses(struct regsvr_coclass const *list);
00057 static HRESULT unregister_coclasses(struct regsvr_coclass const *list);
00058 
00059 struct decoder_pattern
00060 {
00061     DWORD length;    /* 0 for end of list */
00062     DWORD position;
00063     const BYTE *pattern;
00064     const BYTE *mask;
00065     DWORD endofstream;
00066 };
00067 
00068 struct regsvr_decoder
00069 {
00070     CLSID const *clsid;         /* NULL for end of list */
00071     LPCSTR author;
00072     LPCSTR friendlyname;
00073     LPCSTR version;
00074     GUID const *vendor;
00075     LPCSTR mimetypes;
00076     LPCSTR extensions;
00077     GUID const * const *formats;
00078     const struct decoder_pattern *patterns;
00079 };
00080 
00081 static HRESULT register_decoders(struct regsvr_decoder const *list);
00082 static HRESULT unregister_decoders(struct regsvr_decoder const *list);
00083 
00084 struct regsvr_converter
00085 {
00086     CLSID const *clsid;         /* NULL for end of list */
00087     LPCSTR author;
00088     LPCSTR friendlyname;
00089     LPCSTR version;
00090     GUID const *vendor;
00091     GUID const * const *formats;
00092 };
00093 
00094 static HRESULT register_converters(struct regsvr_converter const *list);
00095 static HRESULT unregister_converters(struct regsvr_converter const *list);
00096 
00097 /***********************************************************************
00098  *      static string constants
00099  */
00100 static WCHAR const clsid_keyname[6] = {
00101     'C', 'L', 'S', 'I', 'D', 0 };
00102 static WCHAR const curver_keyname[7] = {
00103     'C', 'u', 'r', 'V', 'e', 'r', 0 };
00104 static WCHAR const ips_keyname[13] = {
00105     'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
00106     0 };
00107 static WCHAR const ips32_keyname[15] = {
00108     'I', 'n', 'P', 'r', 'o', 'c', 'S', 'e', 'r', 'v', 'e', 'r',
00109     '3', '2', 0 };
00110 static WCHAR const progid_keyname[7] = {
00111     'P', 'r', 'o', 'g', 'I', 'D', 0 };
00112 static WCHAR const viprogid_keyname[25] = {
00113     'V', 'e', 'r', 's', 'i', 'o', 'n', 'I', 'n', 'd', 'e', 'p',
00114     'e', 'n', 'd', 'e', 'n', 't', 'P', 'r', 'o', 'g', 'I', 'D',
00115     0 };
00116 static char const tmodel_valuename[] = "ThreadingModel";
00117 static char const author_valuename[] = "Author";
00118 static char const friendlyname_valuename[] = "FriendlyName";
00119 static WCHAR const vendor_valuename[] = {'V','e','n','d','o','r',0};
00120 static char const version_valuename[] = "Version";
00121 static char const mimetypes_valuename[] = "MimeTypes";
00122 static char const extensions_valuename[] = "FileExtensions";
00123 static WCHAR const formats_keyname[] = {'F','o','r','m','a','t','s',0};
00124 static WCHAR const patterns_keyname[] = {'P','a','t','t','e','r','n','s',0};
00125 static WCHAR const instance_keyname[] = {'I','n','s','t','a','n','c','e',0};
00126 static WCHAR const clsid_valuename[] = {'C','L','S','I','D',0};
00127 static char const length_valuename[] = "Length";
00128 static char const position_valuename[] = "Position";
00129 static char const pattern_valuename[] = "Pattern";
00130 static char const mask_valuename[] = "Mask";
00131 static char const endofstream_valuename[] = "EndOfStream";
00132 static WCHAR const pixelformats_keyname[] = {'P','i','x','e','l','F','o','r','m','a','t','s',0};
00133 
00134 /***********************************************************************
00135  *      static helper functions
00136  */
00137 static LONG register_key_defvalueW(HKEY base, WCHAR const *name,
00138                    WCHAR const *value);
00139 static LONG register_key_defvalueA(HKEY base, WCHAR const *name,
00140                    char const *value);
00141 static LONG register_progid(WCHAR const *clsid,
00142                 char const *progid, char const *curver_progid,
00143                 char const *name, char const *extra);
00144 
00145 /***********************************************************************
00146  *      register_coclasses
00147  */
00148 static HRESULT register_coclasses(struct regsvr_coclass const *list)
00149 {
00150     LONG res = ERROR_SUCCESS;
00151     HKEY coclass_key;
00152 
00153     res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
00154               KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
00155     if (res != ERROR_SUCCESS) goto error_return;
00156 
00157     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
00158     WCHAR buf[39];
00159     HKEY clsid_key;
00160 
00161     StringFromGUID2(list->clsid, buf, 39);
00162     res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
00163                   KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
00164     if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00165 
00166     if (list->name) {
00167         res = RegSetValueExA(clsid_key, NULL, 0, REG_SZ,
00168                  (CONST BYTE*)(list->name),
00169                  strlen(list->name) + 1);
00170         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00171     }
00172 
00173     if (list->ips) {
00174         res = register_key_defvalueA(clsid_key, ips_keyname, list->ips);
00175         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00176     }
00177 
00178     if (list->ips32) {
00179         HKEY ips32_key;
00180 
00181         res = RegCreateKeyExW(clsid_key, ips32_keyname, 0, NULL, 0,
00182                   KEY_READ | KEY_WRITE, NULL,
00183                   &ips32_key, NULL);
00184         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00185 
00186         res = RegSetValueExA(ips32_key, NULL, 0, REG_SZ,
00187                  (CONST BYTE*)list->ips32,
00188                  lstrlenA(list->ips32) + 1);
00189         if (res == ERROR_SUCCESS && list->ips32_tmodel)
00190         res = RegSetValueExA(ips32_key, tmodel_valuename, 0, REG_SZ,
00191                      (CONST BYTE*)list->ips32_tmodel,
00192                      strlen(list->ips32_tmodel) + 1);
00193         RegCloseKey(ips32_key);
00194         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00195     }
00196 
00197     if (list->progid) {
00198         res = register_key_defvalueA(clsid_key, progid_keyname,
00199                      list->progid);
00200         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00201 
00202         res = register_progid(buf, list->progid, NULL,
00203                   list->name, list->progid_extra);
00204         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00205     }
00206 
00207     if (list->viprogid) {
00208         res = register_key_defvalueA(clsid_key, viprogid_keyname,
00209                      list->viprogid);
00210         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00211 
00212         res = register_progid(buf, list->viprogid, list->progid,
00213                   list->name, list->progid_extra);
00214         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00215     }
00216 
00217     error_close_clsid_key:
00218     RegCloseKey(clsid_key);
00219     }
00220 
00221 error_close_coclass_key:
00222     RegCloseKey(coclass_key);
00223 error_return:
00224     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00225 }
00226 
00227 /***********************************************************************
00228  *      unregister_coclasses
00229  */
00230 static HRESULT unregister_coclasses(struct regsvr_coclass const *list)
00231 {
00232     LONG res = ERROR_SUCCESS;
00233     HKEY coclass_key;
00234 
00235     res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
00236             KEY_READ | KEY_WRITE, &coclass_key);
00237     if (res == ERROR_FILE_NOT_FOUND) return S_OK;
00238     if (res != ERROR_SUCCESS) goto error_return;
00239 
00240     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
00241     WCHAR buf[39];
00242 
00243     StringFromGUID2(list->clsid, buf, 39);
00244     res = RegDeleteTreeW(coclass_key, buf);
00245     if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00246     if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00247 
00248     if (list->progid) {
00249         res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->progid);
00250         if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00251         if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00252     }
00253 
00254     if (list->viprogid) {
00255         res = RegDeleteTreeA(HKEY_CLASSES_ROOT, list->viprogid);
00256         if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00257         if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00258     }
00259     }
00260 
00261 error_close_coclass_key:
00262     RegCloseKey(coclass_key);
00263 error_return:
00264     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00265 }
00266 
00267 /***********************************************************************
00268  *      register_decoders
00269  */
00270 static HRESULT register_decoders(struct regsvr_decoder const *list)
00271 {
00272     LONG res = ERROR_SUCCESS;
00273     HKEY coclass_key;
00274     WCHAR buf[39];
00275     HKEY decoders_key;
00276     HKEY instance_key;
00277 
00278     res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
00279               KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
00280     if (res == ERROR_SUCCESS)  {
00281         StringFromGUID2(&CATID_WICBitmapDecoders, buf, 39);
00282         res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
00283                   KEY_READ | KEY_WRITE, NULL, &decoders_key, NULL);
00284         if (res == ERROR_SUCCESS)
00285         {
00286             res = RegCreateKeyExW(decoders_key, instance_keyname, 0, NULL, 0,
00287                       KEY_READ | KEY_WRITE, NULL, &instance_key, NULL);
00288             if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00289         }
00290         if (res != ERROR_SUCCESS)
00291             RegCloseKey(coclass_key);
00292     }
00293     if (res != ERROR_SUCCESS) goto error_return;
00294 
00295     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
00296     HKEY clsid_key;
00297     HKEY instance_clsid_key;
00298 
00299     StringFromGUID2(list->clsid, buf, 39);
00300     res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
00301                   KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
00302     if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00303 
00304     StringFromGUID2(list->clsid, buf, 39);
00305     res = RegCreateKeyExW(instance_key, buf, 0, NULL, 0,
00306                   KEY_READ | KEY_WRITE, NULL, &instance_clsid_key, NULL);
00307     if (res == ERROR_SUCCESS) {
00308         res = RegSetValueExW(instance_clsid_key, clsid_valuename, 0, REG_SZ,
00309                  (CONST BYTE*)(buf), 78);
00310         RegCloseKey(instance_clsid_key);
00311     }
00312     if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00313 
00314         if (list->author) {
00315         res = RegSetValueExA(clsid_key, author_valuename, 0, REG_SZ,
00316                  (CONST BYTE*)(list->author),
00317                  strlen(list->author) + 1);
00318         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00319         }
00320 
00321         if (list->friendlyname) {
00322         res = RegSetValueExA(clsid_key, friendlyname_valuename, 0, REG_SZ,
00323                  (CONST BYTE*)(list->friendlyname),
00324                  strlen(list->friendlyname) + 1);
00325         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00326         }
00327 
00328         if (list->vendor) {
00329             StringFromGUID2(list->vendor, buf, 39);
00330         res = RegSetValueExW(clsid_key, vendor_valuename, 0, REG_SZ,
00331                  (CONST BYTE*)(buf), 78);
00332         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00333         }
00334 
00335         if (list->version) {
00336         res = RegSetValueExA(clsid_key, version_valuename, 0, REG_SZ,
00337                  (CONST BYTE*)(list->version),
00338                  strlen(list->version) + 1);
00339         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00340         }
00341 
00342         if (list->mimetypes) {
00343         res = RegSetValueExA(clsid_key, mimetypes_valuename, 0, REG_SZ,
00344                  (CONST BYTE*)(list->mimetypes),
00345                  strlen(list->mimetypes) + 1);
00346         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00347         }
00348 
00349         if (list->extensions) {
00350         res = RegSetValueExA(clsid_key, extensions_valuename, 0, REG_SZ,
00351                  (CONST BYTE*)(list->extensions),
00352                  strlen(list->extensions) + 1);
00353         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00354         }
00355 
00356         if (list->formats) {
00357             HKEY formats_key;
00358             GUID const * const *format;
00359 
00360             res = RegCreateKeyExW(clsid_key, formats_keyname, 0, NULL, 0,
00361                                   KEY_READ | KEY_WRITE, NULL, &formats_key, NULL);
00362             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00363             for (format=list->formats; *format; ++format)
00364             {
00365                 HKEY format_key;
00366                 StringFromGUID2(*format, buf, 39);
00367                 res = RegCreateKeyExW(formats_key, buf, 0, NULL, 0,
00368                                       KEY_READ | KEY_WRITE, NULL, &format_key, NULL);
00369                 if (res != ERROR_SUCCESS) break;
00370                 RegCloseKey(format_key);
00371             }
00372             RegCloseKey(formats_key);
00373             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00374         }
00375 
00376         if (list->patterns) {
00377             HKEY patterns_key;
00378             int i;
00379 
00380             res = RegCreateKeyExW(clsid_key, patterns_keyname, 0, NULL, 0,
00381                                   KEY_READ | KEY_WRITE, NULL, &patterns_key, NULL);
00382             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00383             for (i=0; list->patterns[i].length; i++)
00384             {
00385                 HKEY pattern_key;
00386                 static const WCHAR int_format[] = {'%','i',0};
00387                 snprintfW(buf, 39, int_format, i);
00388                 res = RegCreateKeyExW(patterns_key, buf, 0, NULL, 0,
00389                                       KEY_READ | KEY_WRITE, NULL, &pattern_key, NULL);
00390                 if (res != ERROR_SUCCESS) break;
00391             res = RegSetValueExA(pattern_key, length_valuename, 0, REG_DWORD,
00392                      (CONST BYTE*)(&list->patterns[i].length), 4);
00393                 if (res == ERROR_SUCCESS)
00394                 res = RegSetValueExA(pattern_key, position_valuename, 0, REG_DWORD,
00395                          (CONST BYTE*)(&list->patterns[i].position), 4);
00396                 if (res == ERROR_SUCCESS)
00397                 res = RegSetValueExA(pattern_key, pattern_valuename, 0, REG_BINARY,
00398                          list->patterns[i].pattern,
00399                          list->patterns[i].length);
00400                 if (res == ERROR_SUCCESS)
00401                 res = RegSetValueExA(pattern_key, mask_valuename, 0, REG_BINARY,
00402                          list->patterns[i].mask,
00403                          list->patterns[i].length);
00404                 if (res == ERROR_SUCCESS)
00405                 res = RegSetValueExA(pattern_key, endofstream_valuename, 0, REG_DWORD,
00406                          (CONST BYTE*)&(list->patterns[i].endofstream), 4);
00407                 RegCloseKey(pattern_key);
00408             }
00409             RegCloseKey(patterns_key);
00410             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00411         }
00412 
00413     error_close_clsid_key:
00414     RegCloseKey(clsid_key);
00415     }
00416 
00417 error_close_coclass_key:
00418     RegCloseKey(instance_key);
00419     RegCloseKey(decoders_key);
00420     RegCloseKey(coclass_key);
00421 error_return:
00422     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00423 }
00424 
00425 /***********************************************************************
00426  *      unregister_decoders
00427  */
00428 static HRESULT unregister_decoders(struct regsvr_decoder const *list)
00429 {
00430     LONG res = ERROR_SUCCESS;
00431     HKEY coclass_key;
00432     WCHAR buf[39];
00433     HKEY decoders_key;
00434     HKEY instance_key;
00435 
00436     res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
00437             KEY_READ | KEY_WRITE, &coclass_key);
00438     if (res == ERROR_FILE_NOT_FOUND) return S_OK;
00439 
00440     if (res == ERROR_SUCCESS)  {
00441         StringFromGUID2(&CATID_WICBitmapDecoders, buf, 39);
00442         res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
00443                   KEY_READ | KEY_WRITE, NULL, &decoders_key, NULL);
00444         if (res == ERROR_SUCCESS)
00445         {
00446             res = RegCreateKeyExW(decoders_key, instance_keyname, 0, NULL, 0,
00447                       KEY_READ | KEY_WRITE, NULL, &instance_key, NULL);
00448             if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00449         }
00450         if (res != ERROR_SUCCESS)
00451             RegCloseKey(coclass_key);
00452     }
00453     if (res != ERROR_SUCCESS) goto error_return;
00454 
00455     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
00456     StringFromGUID2(list->clsid, buf, 39);
00457 
00458     res = RegDeleteTreeW(coclass_key, buf);
00459     if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00460     if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00461 
00462     res = RegDeleteTreeW(instance_key, buf);
00463     if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00464     if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00465     }
00466 
00467 error_close_coclass_key:
00468     RegCloseKey(instance_key);
00469     RegCloseKey(decoders_key);
00470     RegCloseKey(coclass_key);
00471 error_return:
00472     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00473 }
00474 
00475 /***********************************************************************
00476  *      register_converters
00477  */
00478 static HRESULT register_converters(struct regsvr_converter const *list)
00479 {
00480     LONG res = ERROR_SUCCESS;
00481     HKEY coclass_key;
00482     WCHAR buf[39];
00483     HKEY converters_key;
00484     HKEY instance_key;
00485 
00486     res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
00487               KEY_READ | KEY_WRITE, NULL, &coclass_key, NULL);
00488     if (res == ERROR_SUCCESS)  {
00489         StringFromGUID2(&CATID_WICFormatConverters, buf, 39);
00490         res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
00491                   KEY_READ | KEY_WRITE, NULL, &converters_key, NULL);
00492         if (res == ERROR_SUCCESS)
00493         {
00494             res = RegCreateKeyExW(converters_key, instance_keyname, 0, NULL, 0,
00495                       KEY_READ | KEY_WRITE, NULL, &instance_key, NULL);
00496             if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00497         }
00498         if (res != ERROR_SUCCESS)
00499             RegCloseKey(coclass_key);
00500     }
00501     if (res != ERROR_SUCCESS) goto error_return;
00502 
00503     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
00504     HKEY clsid_key;
00505     HKEY instance_clsid_key;
00506 
00507     StringFromGUID2(list->clsid, buf, 39);
00508     res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
00509                   KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
00510     if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00511 
00512     StringFromGUID2(list->clsid, buf, 39);
00513     res = RegCreateKeyExW(instance_key, buf, 0, NULL, 0,
00514                   KEY_READ | KEY_WRITE, NULL, &instance_clsid_key, NULL);
00515     if (res == ERROR_SUCCESS) {
00516         res = RegSetValueExW(instance_clsid_key, clsid_valuename, 0, REG_SZ,
00517                  (CONST BYTE*)(buf), 78);
00518         RegCloseKey(instance_clsid_key);
00519     }
00520     if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00521 
00522         if (list->author) {
00523         res = RegSetValueExA(clsid_key, author_valuename, 0, REG_SZ,
00524                  (CONST BYTE*)(list->author),
00525                  strlen(list->author) + 1);
00526         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00527         }
00528 
00529         if (list->friendlyname) {
00530         res = RegSetValueExA(clsid_key, friendlyname_valuename, 0, REG_SZ,
00531                  (CONST BYTE*)(list->friendlyname),
00532                  strlen(list->friendlyname) + 1);
00533         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00534         }
00535 
00536         if (list->vendor) {
00537             StringFromGUID2(list->vendor, buf, 39);
00538         res = RegSetValueExW(clsid_key, vendor_valuename, 0, REG_SZ,
00539                  (CONST BYTE*)(buf), 78);
00540         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00541         }
00542 
00543         if (list->version) {
00544         res = RegSetValueExA(clsid_key, version_valuename, 0, REG_SZ,
00545                  (CONST BYTE*)(list->version),
00546                  strlen(list->version) + 1);
00547         if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00548         }
00549 
00550         if (list->formats) {
00551             HKEY formats_key;
00552             GUID const * const *format;
00553 
00554             res = RegCreateKeyExW(clsid_key, pixelformats_keyname, 0, NULL, 0,
00555                                   KEY_READ | KEY_WRITE, NULL, &formats_key, NULL);
00556             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00557             for (format=list->formats; *format; ++format)
00558             {
00559                 HKEY format_key;
00560                 StringFromGUID2(*format, buf, 39);
00561                 res = RegCreateKeyExW(formats_key, buf, 0, NULL, 0,
00562                                       KEY_READ | KEY_WRITE, NULL, &format_key, NULL);
00563                 if (res != ERROR_SUCCESS) break;
00564                 RegCloseKey(format_key);
00565             }
00566             RegCloseKey(formats_key);
00567             if (res != ERROR_SUCCESS) goto error_close_clsid_key;
00568         }
00569 
00570     error_close_clsid_key:
00571     RegCloseKey(clsid_key);
00572     }
00573 
00574 error_close_coclass_key:
00575     RegCloseKey(instance_key);
00576     RegCloseKey(converters_key);
00577     RegCloseKey(coclass_key);
00578 error_return:
00579     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00580 }
00581 
00582 /***********************************************************************
00583  *      unregister_converters
00584  */
00585 static HRESULT unregister_converters(struct regsvr_converter const *list)
00586 {
00587     LONG res = ERROR_SUCCESS;
00588     HKEY coclass_key;
00589     WCHAR buf[39];
00590     HKEY converters_key;
00591     HKEY instance_key;
00592 
00593     res = RegOpenKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0,
00594             KEY_READ | KEY_WRITE, &coclass_key);
00595     if (res == ERROR_FILE_NOT_FOUND) return S_OK;
00596 
00597     if (res == ERROR_SUCCESS)  {
00598         StringFromGUID2(&CATID_WICFormatConverters, buf, 39);
00599         res = RegCreateKeyExW(coclass_key, buf, 0, NULL, 0,
00600                   KEY_READ | KEY_WRITE, NULL, &converters_key, NULL);
00601         if (res == ERROR_SUCCESS)
00602         {
00603             res = RegCreateKeyExW(converters_key, instance_keyname, 0, NULL, 0,
00604                       KEY_READ | KEY_WRITE, NULL, &instance_key, NULL);
00605             if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00606         }
00607         if (res != ERROR_SUCCESS)
00608             RegCloseKey(coclass_key);
00609     }
00610     if (res != ERROR_SUCCESS) goto error_return;
00611 
00612     for (; res == ERROR_SUCCESS && list->clsid; ++list) {
00613     StringFromGUID2(list->clsid, buf, 39);
00614 
00615     res = RegDeleteTreeW(coclass_key, buf);
00616     if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00617     if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00618 
00619     res = RegDeleteTreeW(instance_key, buf);
00620     if (res == ERROR_FILE_NOT_FOUND) res = ERROR_SUCCESS;
00621     if (res != ERROR_SUCCESS) goto error_close_coclass_key;
00622     }
00623 
00624 error_close_coclass_key:
00625     RegCloseKey(instance_key);
00626     RegCloseKey(converters_key);
00627     RegCloseKey(coclass_key);
00628 error_return:
00629     return res != ERROR_SUCCESS ? HRESULT_FROM_WIN32(res) : S_OK;
00630 }
00631 
00632 /***********************************************************************
00633  *      register_key_defvalueW
00634  */
00635 static LONG register_key_defvalueW(
00636     HKEY base,
00637     WCHAR const *name,
00638     WCHAR const *value)
00639 {
00640     LONG res;
00641     HKEY key;
00642 
00643     res = RegCreateKeyExW(base, name, 0, NULL, 0,
00644               KEY_READ | KEY_WRITE, NULL, &key, NULL);
00645     if (res != ERROR_SUCCESS) return res;
00646     res = RegSetValueExW(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
00647              (lstrlenW(value) + 1) * sizeof(WCHAR));
00648     RegCloseKey(key);
00649     return res;
00650 }
00651 
00652 /***********************************************************************
00653  *      register_key_defvalueA
00654  */
00655 static LONG register_key_defvalueA(
00656     HKEY base,
00657     WCHAR const *name,
00658     char const *value)
00659 {
00660     LONG res;
00661     HKEY key;
00662 
00663     res = RegCreateKeyExW(base, name, 0, NULL, 0,
00664               KEY_READ | KEY_WRITE, NULL, &key, NULL);
00665     if (res != ERROR_SUCCESS) return res;
00666     res = RegSetValueExA(key, NULL, 0, REG_SZ, (CONST BYTE*)value,
00667              lstrlenA(value) + 1);
00668     RegCloseKey(key);
00669     return res;
00670 }
00671 
00672 /***********************************************************************
00673  *      register_progid
00674  */
00675 static LONG register_progid(
00676     WCHAR const *clsid,
00677     char const *progid,
00678     char const *curver_progid,
00679     char const *name,
00680     char const *extra)
00681 {
00682     LONG res;
00683     HKEY progid_key;
00684 
00685     res = RegCreateKeyExA(HKEY_CLASSES_ROOT, progid, 0,
00686               NULL, 0, KEY_READ | KEY_WRITE, NULL,
00687               &progid_key, NULL);
00688     if (res != ERROR_SUCCESS) return res;
00689 
00690     if (name) {
00691     res = RegSetValueExA(progid_key, NULL, 0, REG_SZ,
00692                  (CONST BYTE*)name, strlen(name) + 1);
00693     if (res != ERROR_SUCCESS) goto error_close_progid_key;
00694     }
00695 
00696     if (clsid) {
00697     res = register_key_defvalueW(progid_key, clsid_keyname, clsid);
00698     if (res != ERROR_SUCCESS) goto error_close_progid_key;
00699     }
00700 
00701     if (curver_progid) {
00702     res = register_key_defvalueA(progid_key, curver_keyname,
00703                      curver_progid);
00704     if (res != ERROR_SUCCESS) goto error_close_progid_key;
00705     }
00706 
00707     if (extra) {
00708     HKEY extra_key;
00709 
00710     res = RegCreateKeyExA(progid_key, extra, 0,
00711                   NULL, 0, KEY_READ | KEY_WRITE, NULL,
00712                   &extra_key, NULL);
00713     if (res == ERROR_SUCCESS)
00714         RegCloseKey(extra_key);
00715     }
00716 
00717 error_close_progid_key:
00718     RegCloseKey(progid_key);
00719     return res;
00720 }
00721 
00722 /***********************************************************************
00723  *      coclass list
00724  */
00725 static struct regsvr_coclass const coclass_list[] = {
00726     {   &CLSID_WICImagingFactory,
00727     "WIC Imaging Factory",
00728     NULL,
00729     "windowscodecs.dll",
00730     "Both"
00731     },
00732     {   &CLSID_WICBmpDecoder,
00733     "WIC BMP Decoder",
00734     NULL,
00735     "windowscodecs.dll",
00736     "Both"
00737     },
00738     {   &CLSID_WICPngDecoder,
00739     "WIC PNG Decoder",
00740     NULL,
00741     "windowscodecs.dll",
00742     "Both"
00743     },
00744     {   &CLSID_WICPngEncoder,
00745     "WIC PNG Encoder",
00746     NULL,
00747     "windowscodecs.dll",
00748     "Both"
00749     },
00750     {   &CLSID_WICBmpEncoder,
00751     "WIC BMP Encoder",
00752     NULL,
00753     "windowscodecs.dll",
00754     "Apartment"
00755     },
00756     {   &CLSID_WICGifDecoder,
00757     "WIC GIF Decoder",
00758     NULL,
00759     "windowscodecs.dll",
00760     "Both"
00761     },
00762     {   &CLSID_WICIcoDecoder,
00763     "WIC ICO Decoder",
00764     NULL,
00765     "windowscodecs.dll",
00766     "Both"
00767     },
00768     {   &CLSID_WICJpegDecoder,
00769     "WIC JPEG Decoder",
00770     NULL,
00771     "windowscodecs.dll",
00772     "Both"
00773     },
00774     {   &CLSID_WICTiffDecoder,
00775     "WIC TIFF Decoder",
00776     NULL,
00777     "windowscodecs.dll",
00778     "Both"
00779     },
00780     {   &CLSID_WICDefaultFormatConverter,
00781     "WIC Default Format Converter",
00782     NULL,
00783     "windowscodecs.dll",
00784     "Both"
00785     },
00786     { NULL }            /* list terminator */
00787 };
00788 
00789 /***********************************************************************
00790  *      decoder list
00791  */
00792 static const BYTE mask_all[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
00793 
00794 static const BYTE bmp_magic[] = {0x42,0x4d};
00795 
00796 static GUID const * const bmp_formats[] = {
00797     &GUID_WICPixelFormat1bppIndexed,
00798     &GUID_WICPixelFormat2bppIndexed,
00799     &GUID_WICPixelFormat4bppIndexed,
00800     &GUID_WICPixelFormat8bppIndexed,
00801     &GUID_WICPixelFormat16bppBGR555,
00802     &GUID_WICPixelFormat16bppBGR565,
00803     &GUID_WICPixelFormat24bppBGR,
00804     &GUID_WICPixelFormat32bppBGR,
00805     &GUID_WICPixelFormat32bppBGRA,
00806     NULL
00807 };
00808 
00809 static struct decoder_pattern const bmp_patterns[] = {
00810     {2,0,bmp_magic,mask_all,0},
00811     {0}
00812 };
00813 
00814 static const BYTE gif87a_magic[6] = "GIF87a";
00815 static const BYTE gif89a_magic[6] = "GIF89a";
00816 
00817 static GUID const * const gif_formats[] = {
00818     &GUID_WICPixelFormat8bppIndexed,
00819     NULL
00820 };
00821 
00822 static struct decoder_pattern const gif_patterns[] = {
00823     {6,0,gif87a_magic,mask_all,0},
00824     {6,0,gif89a_magic,mask_all,0},
00825     {0}
00826 };
00827 
00828 static const BYTE ico_magic[] = {00,00,01,00};
00829 
00830 static GUID const * const ico_formats[] = {
00831     &GUID_WICPixelFormat32bppBGRA,
00832     NULL
00833 };
00834 
00835 static struct decoder_pattern const ico_patterns[] = {
00836     {4,0,ico_magic,mask_all,0},
00837     {0}
00838 };
00839 
00840 static const BYTE jpeg_magic[] = {0xff, 0xd8, 0xff, 0xe0};
00841 
00842 static GUID const * const jpeg_formats[] = {
00843     &GUID_WICPixelFormat24bppBGR,
00844     &GUID_WICPixelFormat8bppGray,
00845     NULL
00846 };
00847 
00848 static struct decoder_pattern const jpeg_patterns[] = {
00849     {4,0,jpeg_magic,mask_all,0},
00850     {0}
00851 };
00852 
00853 static const BYTE png_magic[] = {137,80,78,71,13,10,26,10};
00854 
00855 static GUID const * const png_formats[] = {
00856     &GUID_WICPixelFormatBlackWhite,
00857     &GUID_WICPixelFormat2bppGray,
00858     &GUID_WICPixelFormat4bppGray,
00859     &GUID_WICPixelFormat8bppGray,
00860     &GUID_WICPixelFormat16bppGray,
00861     &GUID_WICPixelFormat32bppBGRA,
00862     &GUID_WICPixelFormat64bppRGBA,
00863     &GUID_WICPixelFormat1bppIndexed,
00864     &GUID_WICPixelFormat2bppIndexed,
00865     &GUID_WICPixelFormat4bppIndexed,
00866     &GUID_WICPixelFormat8bppIndexed,
00867     &GUID_WICPixelFormat24bppBGR,
00868     &GUID_WICPixelFormat48bppRGB,
00869     NULL
00870 };
00871 
00872 static struct decoder_pattern const png_patterns[] = {
00873     {8,0,png_magic,mask_all,0},
00874     {0}
00875 };
00876 
00877 static const BYTE tiff_magic_le[] = {0x49,0x49,42,0};
00878 static const BYTE tiff_magic_be[] = {0x4d,0x4d,0,42};
00879 
00880 static GUID const * const tiff_formats[] = {
00881     &GUID_WICPixelFormatBlackWhite,
00882     &GUID_WICPixelFormat4bppGray,
00883     &GUID_WICPixelFormat8bppGray,
00884     &GUID_WICPixelFormat4bppIndexed,
00885     &GUID_WICPixelFormat8bppIndexed,
00886     &GUID_WICPixelFormat32bppBGR,
00887     &GUID_WICPixelFormat32bppBGRA,
00888     &GUID_WICPixelFormat32bppPBGRA,
00889     NULL
00890 };
00891 
00892 static struct decoder_pattern const tiff_patterns[] = {
00893     {4,0,tiff_magic_le,mask_all,0},
00894     {4,0,tiff_magic_be,mask_all,0},
00895     {0}
00896 };
00897 
00898 static struct regsvr_decoder const decoder_list[] = {
00899     {   &CLSID_WICBmpDecoder,
00900     "The Wine Project",
00901     "BMP Decoder",
00902     "1.0.0.0",
00903     &GUID_VendorMicrosoft,
00904     "image/bmp",
00905     ".bmp,.dib,.rle",
00906     bmp_formats,
00907     bmp_patterns
00908     },
00909     {   &CLSID_WICGifDecoder,
00910     "The Wine Project",
00911     "GIF Decoder",
00912     "1.0.0.0",
00913     &GUID_VendorMicrosoft,
00914     "image/gif",
00915     ".gif",
00916     gif_formats,
00917     gif_patterns
00918     },
00919     {   &CLSID_WICIcoDecoder,
00920     "The Wine Project",
00921     "ICO Decoder",
00922     "1.0.0.0",
00923     &GUID_VendorMicrosoft,
00924     "image/vnd.microsoft.icon",
00925     ".ico",
00926     ico_formats,
00927     ico_patterns
00928     },
00929     {   &CLSID_WICJpegDecoder,
00930     "The Wine Project",
00931     "JPEG Decoder",
00932     "1.0.0.0",
00933     &GUID_VendorMicrosoft,
00934     "image/jpeg",
00935     ".jpg;.jpeg;.jfif",
00936     jpeg_formats,
00937     jpeg_patterns
00938     },
00939     {   &CLSID_WICPngDecoder,
00940     "The Wine Project",
00941     "PNG Decoder",
00942     "1.0.0.0",
00943     &GUID_VendorMicrosoft,
00944     "image/png",
00945     ".png",
00946     png_formats,
00947     png_patterns
00948     },
00949     {   &CLSID_WICTiffDecoder,
00950     "The Wine Project",
00951     "TIFF Decoder",
00952     "1.0.0.0",
00953     &GUID_VendorMicrosoft,
00954     "image/tiff",
00955     ".tif;.tiff",
00956     tiff_formats,
00957     tiff_patterns
00958     },
00959     { NULL }            /* list terminator */
00960 };
00961 
00962 static GUID const * const converter_formats[] = {
00963     &GUID_WICPixelFormat1bppIndexed,
00964     &GUID_WICPixelFormat2bppIndexed,
00965     &GUID_WICPixelFormat4bppIndexed,
00966     &GUID_WICPixelFormat8bppIndexed,
00967     &GUID_WICPixelFormatBlackWhite,
00968     &GUID_WICPixelFormat2bppGray,
00969     &GUID_WICPixelFormat4bppGray,
00970     &GUID_WICPixelFormat8bppGray,
00971     &GUID_WICPixelFormat16bppGray,
00972     &GUID_WICPixelFormat16bppBGR555,
00973     &GUID_WICPixelFormat16bppBGR565,
00974     &GUID_WICPixelFormat24bppBGR,
00975     &GUID_WICPixelFormat32bppBGR,
00976     &GUID_WICPixelFormat32bppBGRA,
00977     &GUID_WICPixelFormat48bppRGB,
00978     &GUID_WICPixelFormat64bppRGBA,
00979     NULL
00980 };
00981 
00982 static struct regsvr_converter const converter_list[] = {
00983     {   &CLSID_WICDefaultFormatConverter,
00984     "The Wine Project",
00985     "Default Pixel Format Converter",
00986     "1.0.0.0",
00987     &GUID_VendorMicrosoft,
00988     converter_formats
00989     },
00990     { NULL }            /* list terminator */
00991 };
00992 
00993 HRESULT WINAPI DllRegisterServer(void)
00994 {
00995     HRESULT hr;
00996 
00997     TRACE("\n");
00998 
00999     hr = register_coclasses(coclass_list);
01000     if (SUCCEEDED(hr))
01001         register_decoders(decoder_list);
01002     if (SUCCEEDED(hr))
01003         register_converters(converter_list);
01004     return hr;
01005 }
01006 
01007 HRESULT WINAPI DllUnregisterServer(void)
01008 {
01009     HRESULT hr;
01010 
01011     TRACE("\n");
01012 
01013     hr = unregister_coclasses(coclass_list);
01014     if (SUCCEEDED(hr))
01015         unregister_decoders(decoder_list);
01016     if (SUCCEEDED(hr))
01017         unregister_converters(converter_list);
01018     return hr;
01019 }

Generated on Sat May 26 2012 04:20:05 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.