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

network.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:     ReactX Diagnosis Application
00003  * LICENSE:     LGPL - See COPYING in the top level directory
00004  * FILE:        base/applications/dxdiag/dxdiag.c
00005  * PURPOSE:     ReactX diagnosis network page
00006  * COPYRIGHT:   Copyright 2008 Johannes Anderwald
00007  *
00008  */
00009 
00010 #include "precomp.h"
00011 
00012 typedef struct
00013 {
00014     WCHAR Guid[40];
00015     UINT ResourceID;
00016 }DIRECTPLAY_GUID;
00017 
00018 typedef struct _LANGANDCODEPAGE_
00019   {
00020     WORD lang;
00021     WORD code;
00022 } LANGANDCODEPAGE, *LPLANGANDCODEPAGE;
00023 
00024 static DIRECTPLAY_GUID DirectPlay8SP[] =
00025 {
00026     {
00027         L"{6D4A3650-628D-11D2-AE0F-006097B01411}",
00028         IDS_DIRECTPLAY8_MODEMSP
00029     },
00030     {
00031         L"{743B5D60-628D-11D2-AE0F-006097B01411}",
00032         IDS_DIRECTPLAY8_SERIALSP
00033     },
00034     {
00035         L"{53934290-628D-11D2-AE0F-006097B01411}",
00036         IDS_DIRECTPLAY8_IPXSP
00037     },
00038     {
00039         L"{EBFE7BA0-628D-11D2-AE0F-006097B01411}",
00040         IDS_DIRECTPLAY8_TCPSP
00041     }
00042 };
00043 
00044 static DIRECTPLAY_GUID DirectPlaySP[] = 
00045 {
00046     {
00047         L"{36E95EE0-8577-11cf-960C-0080C7534E82}",
00048         IDS_DIRECTPLAY_TCPCONN
00049     },
00050     {
00051         L"685BC400-9D2C-11cf-A9CD-00AA006886E3",
00052         IDS_DIRECTPLAY_IPXCONN
00053     },
00054     {
00055         L"{44EAA760-CB68-11cf-9C4E-00A0C905425E}",
00056         IDS_DIRECTPLAY_MODEMCONN
00057     },
00058     {
00059         L"{0F1D6860-88D9-11cf-9C4E-00A0C905425E}",
00060         IDS_DIRECTPLAY_SERIALCONN
00061     }
00062 };
00063 
00064 static
00065 VOID
00066 InitListViewColumns(HWND hDlgCtrl)
00067 {
00068     WCHAR szText[256];
00069     LVCOLUMNW lvcolumn;
00070     INT Index;
00071 
00072     ZeroMemory(&lvcolumn, sizeof(LVCOLUMNW));
00073     lvcolumn.pszText = szText;
00074     lvcolumn.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH;
00075     lvcolumn.fmt = LVCFMT_LEFT;
00076     lvcolumn.cx = 200;
00077 
00078     for(Index = 0; Index < 4; Index++)
00079     {
00080         szText[0] = L'\0';
00081         LoadStringW(hInst, IDS_DIRECTPLAY_COL_NAME1 + Index, szText, sizeof(szText) / sizeof(WCHAR));
00082         szText[(sizeof(szText) / sizeof(WCHAR))-1] = L'\0';
00083         if (Index)
00084             lvcolumn.cx = 98;
00085         if (SendMessageW(hDlgCtrl, LVM_INSERTCOLUMNW, Index, (LPARAM)&lvcolumn) == -1)
00086             return;
00087     }
00088 }
00089 
00090 UINT
00091 FindProviderIndex(LPCWSTR szGuid, DIRECTPLAY_GUID * PreDefProviders)
00092 {
00093     UINT Index;
00094     for(Index = 0; Index < 4; Index++)
00095     {
00096         if (!wcsncmp(PreDefProviders[Index].Guid, szGuid, 40))
00097             return Index;
00098     }
00099     return UINT_MAX;
00100 }
00101 
00102 BOOL
00103 GetFileVersion(LPCWSTR szAppName, WCHAR * szVer, DWORD szVerSize)
00104 {
00105     UINT VerSize;
00106     DWORD DummyHandle;
00107     LPVOID pBuf;
00108     WORD lang = 0;
00109     WORD code = 0;
00110     LPLANGANDCODEPAGE lplangcode;
00111     WCHAR szBuffer[100];
00112     WCHAR * pResult;
00113     BOOL bResult = FALSE;
00114     BOOL bVer;
00115 
00116     static const WCHAR wFormat[] = L"\\StringFileInfo\\%04x%04x\\FileVersion";
00117     static const WCHAR wTranslation[] = L"VarFileInfo\\Translation";
00118 
00119     /* query version info size */
00120     VerSize = GetFileVersionInfoSizeW(szAppName, &DummyHandle);
00121     if (!VerSize)
00122         return FALSE;
00123 
00124 
00125     /* allocate buffer */
00126     pBuf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, VerSize);
00127     if (!pBuf)
00128         return FALSE;
00129 
00130 
00131     /* query version info */
00132     if(!GetFileVersionInfoW(szAppName, 0, VerSize, pBuf))
00133     {
00134         HeapFree(GetProcessHeap(), 0, pBuf);
00135         return FALSE;
00136     }
00137 
00138     /* query lang code */
00139     if(VerQueryValueW(pBuf, wTranslation, (LPVOID *)&lplangcode, &VerSize))
00140     {
00141        /* FIXME find language from current locale / if not available,
00142         * default to english
00143         * for now default to first available language
00144         */
00145        lang = lplangcode->lang;
00146        code = lplangcode->code;
00147     }
00148     /* set up format */
00149     wsprintfW(szBuffer, wFormat, lang, code);
00150     /* query manufacturer */
00151      pResult = NULL;
00152     bVer = VerQueryValueW(pBuf, szBuffer, (LPVOID *)&pResult, &VerSize);
00153 
00154     if (VerSize < szVerSize && bVer && pResult)
00155     {
00156         wcscpy(szVer, pResult);
00157         pResult = wcschr(szVer, L' ');
00158         if (pResult)
00159         {
00160             /* cut off build info */
00161             VerSize = (pResult - szVer);
00162         }
00163         if (GetLocaleInfoW(MAKELCID(lang, SORT_DEFAULT), LOCALE_SLANGUAGE, &szVer[VerSize], szVerSize-VerSize))
00164         {
00165             szVer[VerSize-1] = L' ';
00166             szVer[szVerSize-1] = L'\0';
00167         }
00168         bResult = TRUE;
00169     }
00170 
00171     HeapFree(GetProcessHeap(), 0, pBuf);
00172     return bResult;
00173 }
00174 
00175 static
00176 BOOL
00177 EnumerateServiceProviders(HKEY hKey, HWND hDlgCtrl, DIRECTPLAY_GUID * PreDefProviders)
00178 {
00179     DWORD dwIndex = 0;
00180     LONG result;
00181     WCHAR szName[50];
00182     WCHAR szGUID[40];
00183     WCHAR szTemp[63];
00184     WCHAR szResult[MAX_PATH+20] = {0};
00185     DWORD RegProviders = 0;
00186     DWORD ProviderIndex;
00187     DWORD dwName;
00188     LVITEMW Item;
00189     INT ItemCount;
00190     LRESULT lResult;
00191 
00192 
00193     ItemCount = ListView_GetItemCount(hDlgCtrl);
00194     ZeroMemory(&Item, sizeof(LVITEMW));
00195     Item.mask = LVIF_TEXT;
00196     Item.pszText = szResult;
00197     Item.iItem = ItemCount;
00198     /* insert all predefined items first */
00199     for(dwIndex = 0; dwIndex < 4; dwIndex++)
00200     {
00201         Item.iItem = ItemCount + dwIndex;
00202         Item.iSubItem = 0;
00203         szResult[0] = L'\0';
00204         LoadStringW(hInst, PreDefProviders[dwIndex].ResourceID, szResult, sizeof(szResult)/sizeof(WCHAR));
00205         szResult[(sizeof(szResult)/sizeof(WCHAR))-1] = L'\0';
00206         Item.iItem = SendMessageW(hDlgCtrl, LVM_INSERTITEM, 0, (LPARAM)&Item);
00207         Item.iSubItem = 1;
00208         szResult[0] = L'\0';
00209         LoadStringW(hInst, IDS_REG_FAIL, szResult, sizeof(szResult)/sizeof(WCHAR));
00210         szResult[(sizeof(szResult)/sizeof(WCHAR))-1] = L'\0';
00211         SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
00212     }
00213 
00214     dwIndex = 0;
00215     do
00216     {
00217         dwName = sizeof(szName) / sizeof(WCHAR);
00218         result = RegEnumKeyEx(hKey, dwIndex, szName, &dwName, NULL, NULL, NULL, NULL);
00219         if (result == ERROR_SUCCESS)
00220         {
00221             szName[(sizeof(szName)/sizeof(WCHAR))-1] = L'\0';
00222 
00223             ProviderIndex = UINT_MAX;
00224             if (GetRegValue(hKey, szName, L"GUID", REG_SZ, szGUID, sizeof(szGUID)))
00225                 ProviderIndex = FindProviderIndex(szGUID, PreDefProviders);
00226 
00227             if (ProviderIndex == UINT_MAX)
00228             {
00229                 /* a custom service provider was found */
00230                 Item.iItem = ListView_GetItemCount(hDlgCtrl);
00231 
00232                 /* FIXME
00233                  * on Windows Vista we need to use RegLoadMUIString which is not available for older systems 
00234                  */
00235                 if (!GetRegValue(hKey, szName, L"Friendly Name", REG_SZ, szResult, sizeof(szResult)))
00236                     if (!GetRegValue(hKey, szName, L"DescriptionW", REG_SZ, szResult, sizeof(szResult)))
00237                         szResult[0] = L'\0';
00238 
00239                 /* insert the new provider */
00240                 Item.iSubItem = 0;
00241                 lResult = SendMessageW(hDlgCtrl, LVM_INSERTITEM, 0, (LPARAM)&Item);
00242                 /* adjust index */
00243                 ProviderIndex = lResult - ItemCount;
00244             }
00245 
00246             szResult[0] = L'\0';
00247             /* check if the 'Path' key is available */
00248             if (!GetRegValue(hKey, szName, L"Path", REG_SZ, szResult, sizeof(szResult)))
00249             {
00250                 /* retrieve the path by lookup the CLSID */
00251                 wcscpy(szTemp, L"CLSID\\");
00252                 wcscpy(&szTemp[6], szGUID);
00253                 wcscpy(&szTemp[44], L"\\InProcServer32");
00254                 if (!GetRegValue(HKEY_CLASSES_ROOT, szTemp, NULL, REG_SZ, szResult, sizeof(szResult)))
00255                 {
00256                     szResult[0] = L'\0';
00257                     ProviderIndex = UINT_MAX;
00258                 }
00259             }
00260             if (szResult[0])
00261             {
00262                 /* insert path name */
00263                 Item.iSubItem = 2;
00264                 Item.iItem = ProviderIndex + ItemCount;
00265                 SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
00266                 /* retrieve file version */
00267                 if (!GetFileVersion(szResult, szTemp, sizeof(szTemp)/sizeof(WCHAR)))
00268                 {
00269                     szTemp[0] = L'\0';
00270                     LoadStringW(hInst, IDS_VERSION_UNKNOWN, szTemp, sizeof(szTemp)/sizeof(WCHAR));
00271                     szTemp[(sizeof(szTemp)/sizeof(WCHAR))-1] = L'\0';
00272                 }
00273                 Item.iSubItem = 3;
00274                 Item.pszText = szTemp;
00275                 SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
00276                 Item.pszText = szResult;
00277             }
00278 
00279              if (ProviderIndex != UINT_MAX)
00280                 {
00281                     RegProviders |= (1 << ProviderIndex);
00282                     szResult[0] = L'\0';
00283                     LoadStringW(hInst, IDS_REG_SUCCESS, szResult, sizeof(szResult));
00284                     Item.iSubItem = 1;
00285 
00286                     Item.iItem = ProviderIndex + ItemCount;
00287                     szResult[(sizeof(szResult)/sizeof(WCHAR))-1] = L'\0';
00288                     SendMessageW(hDlgCtrl, LVM_SETITEM, 0, (LPARAM)&Item);
00289                 }
00290         }
00291         dwIndex++;
00292     }while(result != ERROR_NO_MORE_ITEMS);
00293 
00294     /* check if all providers have been registered */
00295 //    if (RegProviders == 15)
00296         return TRUE;
00297     return FALSE;
00298 }
00299 
00300 
00301 
00302 static
00303 void
00304 InitializeDirectPlayDialog(HWND hwndDlg)
00305 {
00306     HKEY hKey;
00307     LONG result;
00308     HWND hDlgCtrl;
00309 
00310     /* open DirectPlay8 key */
00311     result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectPlay8\\Service Providers", 0, KEY_READ, &hKey);
00312     if (result != ERROR_SUCCESS)
00313         return;
00314 
00315     hDlgCtrl = GetDlgItem(hwndDlg, IDC_LIST_PROVIDER);
00316     /* initialize list ctrl */
00317     InitListViewColumns(hDlgCtrl);
00318 
00319     /* enumerate providers */
00320     result = EnumerateServiceProviders(hKey, hDlgCtrl, DirectPlay8SP);
00321     RegCloseKey(hKey);
00322     if (!result)
00323         return;
00324 
00325     /* open DirectPlay key */
00326     result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectPlay\\Service Providers", 0, KEY_READ, &hKey);
00327     if (result != ERROR_SUCCESS)
00328         return;
00329 
00330     /* enumerate providers */
00331     EnumerateServiceProviders(hKey, hDlgCtrl, DirectPlaySP);
00332     RegCloseKey(hKey);
00333 }
00334 
00335 INT_PTR CALLBACK
00336 NetworkPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
00337 {
00338     UNREFERENCED_PARAMETER(lParam);
00339     UNREFERENCED_PARAMETER(wParam);
00340     switch (message) {
00341         case WM_INITDIALOG:
00342         {
00343             SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
00344             InitializeDirectPlayDialog(hDlg);
00345             return TRUE;
00346         }
00347     }
00348 
00349     return FALSE;
00350 }

Generated on Sat May 26 2012 04:15:36 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.