Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenedit.c
Go to the documentation of this file.
00001 /* 00002 * Registry editing UI functions. 00003 * 00004 * Copyright (C) 2003 Dimitrie O. Paun 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #include <regedit.h> 00022 00023 typedef enum _EDIT_MODE 00024 { 00025 EDIT_MODE_DEC, 00026 EDIT_MODE_HEX 00027 } EDIT_MODE; 00028 00029 00030 static const TCHAR* editValueName; 00031 static TCHAR* stringValueData; 00032 static PVOID binValueData; 00033 static DWORD dwordValueData; 00034 static PCM_RESOURCE_LIST resourceValueData; 00035 static INT fullResourceIndex = -1; 00036 static DWORD valueDataLen; 00037 static EDIT_MODE dwordEditMode = EDIT_MODE_HEX; 00038 00039 void error(HWND hwnd, INT resId, ...) 00040 { 00041 va_list ap; 00042 TCHAR title[256]; 00043 TCHAR errfmt[1024]; 00044 TCHAR errstr[1024]; 00045 HINSTANCE hInstance; 00046 00047 hInstance = GetModuleHandle(0); 00048 00049 if (!LoadString(hInstance, IDS_ERROR, title, COUNT_OF(title))) 00050 _tcscpy(title, _T("Error")); 00051 00052 if (!LoadString(hInstance, resId, errfmt, COUNT_OF(errfmt))) 00053 _tcscpy(errfmt, _T("Unknown error string!")); 00054 00055 va_start(ap, resId); 00056 _vsntprintf(errstr, COUNT_OF(errstr), errfmt, ap); 00057 va_end(ap); 00058 00059 MessageBox(hwnd, errstr, title, MB_OK | MB_ICONERROR); 00060 } 00061 00062 static void error_code_messagebox(HWND hwnd, DWORD error_code) 00063 { 00064 TCHAR title[256]; 00065 if (!LoadString(hInst, IDS_ERROR, title, COUNT_OF(title))) 00066 lstrcpy(title, TEXT("Error")); 00067 ErrorMessageBox(hwnd, title, error_code); 00068 } 00069 00070 void warning(HWND hwnd, INT resId, ...) 00071 { 00072 va_list ap; 00073 TCHAR title[256]; 00074 TCHAR errfmt[1024]; 00075 TCHAR errstr[1024]; 00076 HINSTANCE hInstance; 00077 00078 hInstance = GetModuleHandle(0); 00079 00080 if (!LoadString(hInstance, IDS_WARNING, title, COUNT_OF(title))) 00081 _tcscpy(title, _T("Warning")); 00082 00083 if (!LoadString(hInstance, resId, errfmt, COUNT_OF(errfmt))) 00084 _tcscpy(errfmt, _T("Unknown error string!")); 00085 00086 va_start(ap, resId); 00087 _vsntprintf(errstr, COUNT_OF(errstr), errfmt, ap); 00088 va_end(ap); 00089 00090 MessageBox(hwnd, errstr, title, MB_OK | MB_ICONSTOP); 00091 } 00092 00093 INT_PTR CALLBACK modify_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 00094 { 00095 TCHAR* valueData; 00096 HWND hwndValue; 00097 int len; 00098 00099 UNREFERENCED_PARAMETER(lParam); 00100 00101 switch(uMsg) 00102 { 00103 case WM_INITDIALOG: 00104 if(editValueName && _tcscmp(editValueName, _T(""))) 00105 { 00106 SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); 00107 } 00108 else 00109 { 00110 TCHAR buffer[255]; 00111 LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); 00112 SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); 00113 } 00114 SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData); 00115 SetFocus(GetDlgItem(hwndDlg, IDC_VALUE_DATA)); 00116 return FALSE; 00117 case WM_COMMAND: 00118 switch (LOWORD(wParam)) 00119 { 00120 case IDOK: 00121 if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) 00122 { 00123 if ((len = GetWindowTextLength(hwndValue))) 00124 { 00125 if (stringValueData) 00126 { 00127 if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(TCHAR)))) 00128 { 00129 stringValueData = valueData; 00130 if (!GetWindowText(hwndValue, stringValueData, len + 1)) 00131 *stringValueData = 0; 00132 } 00133 } 00134 else 00135 { 00136 if ((valueData = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(TCHAR)))) 00137 { 00138 stringValueData = valueData; 00139 if (!GetWindowText(hwndValue, stringValueData, len + 1)) 00140 *stringValueData = 0; 00141 } 00142 } 00143 } 00144 else 00145 { 00146 if (stringValueData) 00147 *stringValueData = 0; 00148 } 00149 } 00150 EndDialog(hwndDlg, IDOK); 00151 break; 00152 case IDCANCEL: 00153 EndDialog(hwndDlg, IDCANCEL); 00154 return TRUE; 00155 } 00156 } 00157 return FALSE; 00158 } 00159 00160 00161 INT_PTR CALLBACK modify_multi_string_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 00162 { 00163 TCHAR* valueData; 00164 HWND hwndValue; 00165 int len; 00166 00167 UNREFERENCED_PARAMETER(lParam); 00168 00169 switch(uMsg) 00170 { 00171 case WM_INITDIALOG: 00172 if(editValueName && _tcscmp(editValueName, _T(""))) 00173 { 00174 SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); 00175 } 00176 else 00177 { 00178 TCHAR buffer[255]; 00179 LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); 00180 SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); 00181 } 00182 SetDlgItemText(hwndDlg, IDC_VALUE_DATA, stringValueData); 00183 SetFocus(GetDlgItem(hwndDlg, IDC_VALUE_DATA)); 00184 return FALSE; 00185 case WM_COMMAND: 00186 switch (LOWORD(wParam)) 00187 { 00188 case IDOK: 00189 if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) 00190 { 00191 if ((len = GetWindowTextLength(hwndValue))) 00192 { 00193 if (stringValueData) 00194 { 00195 if ((valueData = HeapReAlloc(GetProcessHeap(), 0, stringValueData, (len + 1) * sizeof(TCHAR)))) 00196 { 00197 stringValueData = valueData; 00198 if (!GetWindowText(hwndValue, stringValueData, len + 1)) 00199 *stringValueData = 0; 00200 } 00201 } 00202 else 00203 { 00204 if ((valueData = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(TCHAR)))) 00205 { 00206 stringValueData = valueData; 00207 if (!GetWindowText(hwndValue, stringValueData, len + 1)) 00208 *stringValueData = 0; 00209 } 00210 } 00211 } 00212 else 00213 { 00214 if (stringValueData) 00215 *stringValueData = 0; 00216 } 00217 } 00218 EndDialog(hwndDlg, IDOK); 00219 break; 00220 case IDCANCEL: 00221 EndDialog(hwndDlg, IDCANCEL); 00222 return TRUE; 00223 } 00224 } 00225 return FALSE; 00226 } 00227 00228 00229 LRESULT CALLBACK DwordEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 00230 { 00231 WNDPROC oldwndproc; 00232 00233 oldwndproc = (WNDPROC)(LONG_PTR)GetWindowLongPtr(hwnd, GWL_USERDATA); 00234 00235 switch (uMsg) 00236 { 00237 case WM_CHAR: 00238 if (dwordEditMode == EDIT_MODE_DEC) 00239 { 00240 if (isdigit((int) wParam & 0xff) || iscntrl((int) wParam & 0xff)) 00241 { 00242 break; 00243 } 00244 else 00245 { 00246 return 0; 00247 } 00248 } 00249 else if (dwordEditMode == EDIT_MODE_HEX) 00250 { 00251 if (isxdigit((int) wParam & 0xff) || iscntrl((int) wParam & 0xff)) 00252 { 00253 break; 00254 } 00255 else 00256 { 00257 return 0; 00258 } 00259 } 00260 else 00261 { 00262 break; 00263 } 00264 } 00265 00266 return CallWindowProc(oldwndproc, hwnd, uMsg, wParam, lParam); 00267 } 00268 00269 00270 INT_PTR CALLBACK modify_dword_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 00271 { 00272 WNDPROC oldproc; 00273 HWND hwndValue; 00274 TCHAR ValueString[32]; 00275 LPTSTR Remainder; 00276 DWORD Base; 00277 DWORD Value = 0; 00278 00279 UNREFERENCED_PARAMETER(lParam); 00280 00281 switch(uMsg) 00282 { 00283 case WM_INITDIALOG: 00284 dwordEditMode = EDIT_MODE_HEX; 00285 00286 /* subclass the edit control */ 00287 hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA); 00288 oldproc = (WNDPROC)(LONG_PTR)GetWindowLongPtr(hwndValue, GWL_WNDPROC); 00289 SetWindowLongPtr(hwndValue, GWL_USERDATA, (DWORD_PTR)oldproc); 00290 SetWindowLongPtr(hwndValue, GWL_WNDPROC, (DWORD_PTR)DwordEditSubclassProc); 00291 00292 if(editValueName && _tcscmp(editValueName, _T(""))) 00293 { 00294 SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); 00295 } 00296 else 00297 { 00298 TCHAR buffer[255]; 00299 LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); 00300 SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); 00301 } 00302 CheckRadioButton (hwndDlg, IDC_FORMAT_HEX, IDC_FORMAT_DEC, IDC_FORMAT_HEX); 00303 _stprintf (ValueString, _T("%lx"), dwordValueData); 00304 SetDlgItemText(hwndDlg, IDC_VALUE_DATA, ValueString); 00305 SetFocus(GetDlgItem(hwndDlg, IDC_VALUE_DATA)); 00306 return FALSE; 00307 00308 case WM_COMMAND: 00309 switch (LOWORD(wParam)) 00310 { 00311 case IDC_FORMAT_HEX: 00312 if (HIWORD(wParam) == BN_CLICKED && dwordEditMode == EDIT_MODE_DEC) 00313 { 00314 dwordEditMode = EDIT_MODE_HEX; 00315 if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) 00316 { 00317 if (GetWindowTextLength(hwndValue)) 00318 { 00319 if (GetWindowText(hwndValue, ValueString, 32)) 00320 { 00321 Value = _tcstoul (ValueString, &Remainder, 10); 00322 } 00323 } 00324 } 00325 _stprintf (ValueString, _T("%lx"), Value); 00326 SetDlgItemText(hwndDlg, IDC_VALUE_DATA, ValueString); 00327 return TRUE; 00328 } 00329 break; 00330 00331 case IDC_FORMAT_DEC: 00332 if (HIWORD(wParam) == BN_CLICKED && dwordEditMode == EDIT_MODE_HEX) 00333 { 00334 dwordEditMode = EDIT_MODE_DEC; 00335 if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) 00336 { 00337 if (GetWindowTextLength(hwndValue)) 00338 { 00339 if (GetWindowText(hwndValue, ValueString, 32)) 00340 { 00341 Value = _tcstoul (ValueString, &Remainder, 16); 00342 } 00343 } 00344 } 00345 _stprintf (ValueString, _T("%lu"), Value); 00346 SetDlgItemText(hwndDlg, IDC_VALUE_DATA, ValueString); 00347 return TRUE; 00348 } 00349 break; 00350 00351 case IDOK: 00352 if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) 00353 { 00354 if (GetWindowTextLength(hwndValue)) 00355 { 00356 if (!GetWindowText(hwndValue, ValueString, 32)) 00357 { 00358 EndDialog(hwndDlg, IDCANCEL); 00359 return TRUE; 00360 } 00361 00362 Base = (dwordEditMode == EDIT_MODE_HEX) ? 16 : 10; 00363 dwordValueData = _tcstoul (ValueString, &Remainder, Base); 00364 } 00365 else 00366 { 00367 EndDialog(hwndDlg, IDCANCEL); 00368 return TRUE; 00369 } 00370 } 00371 EndDialog(hwndDlg, IDOK); 00372 return TRUE; 00373 00374 case IDCANCEL: 00375 EndDialog(hwndDlg, IDCANCEL); 00376 return TRUE; 00377 } 00378 } 00379 return FALSE; 00380 } 00381 00382 00383 INT_PTR CALLBACK modify_binary_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 00384 { 00385 HWND hwndValue; 00386 UINT len; 00387 00388 UNREFERENCED_PARAMETER(lParam); 00389 00390 switch(uMsg) 00391 { 00392 case WM_INITDIALOG: 00393 if(editValueName && _tcscmp(editValueName, _T(""))) 00394 { 00395 SetDlgItemText(hwndDlg, IDC_VALUE_NAME, editValueName); 00396 } 00397 else 00398 { 00399 TCHAR buffer[255]; 00400 LoadString(hInst, IDS_DEFAULT_VALUE_NAME, buffer, sizeof(buffer)/sizeof(TCHAR)); 00401 SetDlgItemText(hwndDlg, IDC_VALUE_NAME, buffer); 00402 } 00403 hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA); 00404 HexEdit_LoadBuffer(hwndValue, binValueData, valueDataLen); 00405 /* reset the hex edit control's font */ 00406 SendMessage(hwndValue, WM_SETFONT, 0, 0); 00407 SetFocus(hwndValue); 00408 return FALSE; 00409 case WM_COMMAND: 00410 switch (LOWORD(wParam)) 00411 { 00412 case IDOK: 00413 if ((hwndValue = GetDlgItem(hwndDlg, IDC_VALUE_DATA))) 00414 { 00415 len = (UINT) HexEdit_GetBufferSize(hwndValue); 00416 if (len > 0 && binValueData) 00417 binValueData = HeapReAlloc(GetProcessHeap(), 0, binValueData, len); 00418 else 00419 binValueData = HeapAlloc(GetProcessHeap(), 0, len + 1); 00420 HexEdit_CopyBuffer(hwndValue, binValueData, len); 00421 valueDataLen = len; 00422 } 00423 EndDialog(hwndDlg, IDOK); 00424 break; 00425 case IDCANCEL: 00426 EndDialog(hwndDlg, IDCANCEL); 00427 return TRUE; 00428 } 00429 } 00430 return FALSE; 00431 } 00432 00433 00434 static BOOL CreateResourceColumns(HWND hwnd) 00435 { 00436 TCHAR szText[80]; 00437 RECT rc; 00438 LV_COLUMN lvC; 00439 HWND hwndLV; 00440 INT width; 00441 00442 /* Create columns. */ 00443 lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; 00444 lvC.pszText = szText; 00445 lvC.fmt = LVCFMT_LEFT; 00446 00447 hwndLV = GetDlgItem(hwnd, IDC_DMA_LIST); 00448 ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT); 00449 GetClientRect(hwndLV, &rc); 00450 00451 /* Load the column labels from the resource file. */ 00452 lvC.iSubItem = 0; 00453 lvC.cx = (rc.right - rc.left) / 2; 00454 LoadString(hInst, IDS_DMA_CHANNEL, szText, sizeof(szText)/sizeof(TCHAR)); 00455 if (ListView_InsertColumn(hwndLV, 0, &lvC) == -1) 00456 return FALSE; 00457 00458 lvC.iSubItem = 1; 00459 lvC.cx = (rc.right - rc.left) - lvC.cx; 00460 LoadString(hInst, IDS_DMA_PORT, szText, sizeof(szText)/sizeof(TCHAR)); 00461 if (ListView_InsertColumn(hwndLV, 1, &lvC) == -1) 00462 return FALSE; 00463 00464 00465 /* Interrupt list */ 00466 hwndLV = GetDlgItem(hwnd, IDC_IRQ_LIST); 00467 ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT); 00468 GetClientRect(hwndLV, &rc); 00469 width = (rc.right - rc.left) / 4; 00470 00471 /* Load the column labels from the resource file. */ 00472 lvC.iSubItem = 0; 00473 lvC.cx = width; 00474 LoadString(hInst, IDS_INTERRUPT_VECTOR, szText, sizeof(szText)/sizeof(TCHAR)); 00475 if (ListView_InsertColumn(hwndLV, 0, &lvC) == -1) 00476 return FALSE; 00477 00478 lvC.iSubItem = 1; 00479 LoadString(hInst, IDS_INTERRUPT_LEVEL, szText, sizeof(szText)/sizeof(TCHAR)); 00480 if (ListView_InsertColumn(hwndLV, 1, &lvC) == -1) 00481 return FALSE; 00482 00483 lvC.iSubItem = 2; 00484 LoadString(hInst, IDS_INTERRUPT_AFFINITY, szText, sizeof(szText)/sizeof(TCHAR)); 00485 if (ListView_InsertColumn(hwndLV, 2, &lvC) == -1) 00486 return FALSE; 00487 00488 lvC.iSubItem = 3; 00489 lvC.cx = (rc.right - rc.left) - 3 * width; 00490 LoadString(hInst, IDS_INTERRUPT_TYPE, szText, sizeof(szText)/sizeof(TCHAR)); 00491 if (ListView_InsertColumn(hwndLV, 3, &lvC) == -1) 00492 return FALSE; 00493 00494 00495 /* Memory list */ 00496 hwndLV = GetDlgItem(hwnd, IDC_MEMORY_LIST); 00497 ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT); 00498 GetClientRect(hwndLV, &rc); 00499 width = (rc.right - rc.left) / 3; 00500 00501 /* Load the column labels from the resource file. */ 00502 lvC.iSubItem = 0; 00503 lvC.cx = width; 00504 LoadString(hInst, IDS_MEMORY_ADDRESS, szText, sizeof(szText)/sizeof(TCHAR)); 00505 if (ListView_InsertColumn(hwndLV, 0, &lvC) == -1) 00506 return FALSE; 00507 00508 lvC.iSubItem = 1; 00509 LoadString(hInst, IDS_MEMORY_LENGTH, szText, sizeof(szText)/sizeof(TCHAR)); 00510 if (ListView_InsertColumn(hwndLV, 1, &lvC) == -1) 00511 return FALSE; 00512 00513 lvC.iSubItem = 2; 00514 lvC.cx = (rc.right - rc.left) - 2 * width; 00515 LoadString(hInst, IDS_MEMORY_ACCESS, szText, sizeof(szText)/sizeof(TCHAR)); 00516 if (ListView_InsertColumn(hwndLV, 2, &lvC) == -1) 00517 return FALSE; 00518 00519 00520 /* Port list */ 00521 hwndLV = GetDlgItem(hwnd, IDC_PORT_LIST); 00522 ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT); 00523 GetClientRect(hwndLV, &rc); 00524 width = (rc.right - rc.left) / 3; 00525 00526 /* Load the column labels from the resource file. */ 00527 lvC.iSubItem = 0; 00528 lvC.cx = width; 00529 LoadString(hInst, IDS_PORT_ADDRESS, szText, sizeof(szText)/sizeof(TCHAR)); 00530 if (ListView_InsertColumn(hwndLV, 0, &lvC) == -1) 00531 return FALSE; 00532 00533 lvC.iSubItem = 1; 00534 LoadString(hInst, IDS_PORT_LENGTH, szText, sizeof(szText)/sizeof(TCHAR)); 00535 if (ListView_InsertColumn(hwndLV, 1, &lvC) == -1) 00536 return FALSE; 00537 00538 lvC.iSubItem = 2; 00539 lvC.cx = (rc.right - rc.left) - 2 * width; 00540 LoadString(hInst, IDS_PORT_ACCESS, szText, sizeof(szText)/sizeof(TCHAR)); 00541 if (ListView_InsertColumn(hwndLV, 2, &lvC) == -1) 00542 return FALSE; 00543 00544 /* Device specific list */ 00545 hwndLV = GetDlgItem(hwnd, IDC_DEVICE_LIST); 00546 ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT); 00547 GetClientRect(hwndLV, &rc); 00548 width = (rc.right - rc.left) / 3; 00549 00550 /* Load the column labels from the resource file. */ 00551 lvC.iSubItem = 0; 00552 lvC.cx = width; 00553 LoadString(hInst, IDS_SPECIFIC_RESERVED1, szText, sizeof(szText)/sizeof(TCHAR)); 00554 if (ListView_InsertColumn(hwndLV, 0, &lvC) == -1) 00555 return FALSE; 00556 00557 lvC.iSubItem = 1; 00558 LoadString(hInst, IDS_SPECIFIC_RESERVED2, szText, sizeof(szText)/sizeof(TCHAR)); 00559 if (ListView_InsertColumn(hwndLV, 1, &lvC) == -1) 00560 return FALSE; 00561 00562 lvC.iSubItem = 2; 00563 lvC.cx = (rc.right - rc.left) - 2 * width; 00564 LoadString(hInst, IDS_SPECIFIC_DATASIZE, szText, sizeof(szText)/sizeof(TCHAR)); 00565 if (ListView_InsertColumn(hwndLV, 2, &lvC) == -1) 00566 return FALSE; 00567 00568 return TRUE; 00569 } 00570 00571 static VOID 00572 GetInterfaceType(INTERFACE_TYPE InterfaceType, 00573 LPTSTR pBuffer, 00574 DWORD dwLength) 00575 { 00576 // LPTSTR lpInterfaceType; 00577 00578 switch (InterfaceType) 00579 { 00580 case InterfaceTypeUndefined: 00581 LoadString(hInst, IDS_BUS_UNDEFINED, pBuffer, dwLength); 00582 // lpInterfaceType = _T("Undefined"); 00583 break; 00584 case Internal: 00585 LoadString(hInst, IDS_BUS_INTERNAL, pBuffer, dwLength); 00586 // lpInterfaceType = _T("Internal"); 00587 break; 00588 case Isa: 00589 LoadString(hInst, IDS_BUS_ISA, pBuffer, dwLength); 00590 // lpInterfaceType = _T("Isa"); 00591 break; 00592 case Eisa: 00593 LoadString(hInst, IDS_BUS_EISA, pBuffer, dwLength); 00594 // lpInterfaceType = _T("Eisa"); 00595 break; 00596 case MicroChannel: 00597 LoadString(hInst, IDS_BUS_MICROCHANNEL, pBuffer, dwLength); 00598 // lpInterfaceType = _T("MicroChannel"); 00599 break; 00600 case TurboChannel: 00601 LoadString(hInst, IDS_BUS_TURBOCHANNEL, pBuffer, dwLength); 00602 // lpInterfaceType = _T("TurboChannel"); 00603 break; 00604 case PCIBus: 00605 LoadString(hInst, IDS_BUS_PCIBUS, pBuffer, dwLength); 00606 // lpInterfaceType = _T("PCIBus"); 00607 break; 00608 case VMEBus: 00609 LoadString(hInst, IDS_BUS_VMEBUS, pBuffer, dwLength); 00610 // lpInterfaceType = _T("VMEBus"); 00611 break; 00612 case NuBus: 00613 LoadString(hInst, IDS_BUS_NUBUS, pBuffer, dwLength); 00614 // lpInterfaceType = _T("NuBus"); 00615 break; 00616 case PCMCIABus: 00617 LoadString(hInst, IDS_BUS_PCMCIABUS, pBuffer, dwLength); 00618 // lpInterfaceType = _T("PCMCIABus"); 00619 break; 00620 case CBus: 00621 LoadString(hInst, IDS_BUS_CBUS, pBuffer, dwLength); 00622 // lpInterfaceType = _T("CBus"); 00623 break; 00624 case MPIBus: 00625 LoadString(hInst, IDS_BUS_MPIBUS, pBuffer, dwLength); 00626 // lpInterfaceType = _T("MPIBus"); 00627 break; 00628 case MPSABus: 00629 LoadString(hInst, IDS_BUS_MPSABUS, pBuffer, dwLength); 00630 // lpInterfaceType = _T("MPSABus"); 00631 break; 00632 case ProcessorInternal: 00633 LoadString(hInst, IDS_BUS_PROCESSORINTERNAL, pBuffer, dwLength); 00634 // lpInterfaceType = _T("ProcessorInternal"); 00635 break; 00636 case InternalPowerBus: 00637 LoadString(hInst, IDS_BUS_INTERNALPOWERBUS, pBuffer, dwLength); 00638 // lpInterfaceType = _T("InternalPowerBus"); 00639 break; 00640 case PNPISABus: 00641 LoadString(hInst, IDS_BUS_PNPISABUS, pBuffer, dwLength); 00642 // lpInterfaceType = _T("PNPISABus"); 00643 break; 00644 case PNPBus: 00645 LoadString(hInst, IDS_BUS_PNPBUS, pBuffer, dwLength); 00646 // lpInterfaceType = _T("PNPBus"); 00647 break; 00648 default: 00649 LoadString(hInst, IDS_BUS_UNKNOWNTYPE, pBuffer, dwLength); 00650 // lpInterfaceType = _T("Unknown interface type"); 00651 break; 00652 } 00653 00654 // _tcscpy(pBuffer, lpInterfaceType); 00655 } 00656 00657 00658 static VOID 00659 ParseResources(HWND hwnd) 00660 { 00661 PCM_FULL_RESOURCE_DESCRIPTOR pFullDescriptor; 00662 PCM_PARTIAL_RESOURCE_LIST pPartialResourceList; 00663 PCM_PARTIAL_RESOURCE_DESCRIPTOR pDescriptor; 00664 ULONG i; 00665 HWND hwndLV; 00666 00667 TCHAR buffer[80]; 00668 LVITEM item; 00669 INT iItem; 00670 00671 pFullDescriptor = &resourceValueData->List[fullResourceIndex]; 00672 pPartialResourceList = &pFullDescriptor->PartialResourceList; 00673 00674 /* Interface type */ 00675 GetInterfaceType(pFullDescriptor->InterfaceType, buffer, 80); 00676 SetDlgItemText(hwnd, IDC_INTERFACETYPE, buffer); 00677 00678 /* Busnumber */ 00679 SetDlgItemInt(hwnd, IDC_BUSNUMBER, (UINT)pFullDescriptor->BusNumber, FALSE); 00680 00681 /* Version */ 00682 SetDlgItemInt(hwnd, IDC_VERSION, (UINT)pPartialResourceList->Version, FALSE); 00683 00684 /* Revision */ 00685 SetDlgItemInt(hwnd, IDC_REVISION, (UINT)pPartialResourceList->Revision, FALSE); 00686 00687 for (i = 0; i < pPartialResourceList->Count; i++) 00688 { 00689 pDescriptor = &pPartialResourceList->PartialDescriptors[i]; 00690 00691 switch (pDescriptor->Type) 00692 { 00693 case CmResourceTypePort: 00694 hwndLV = GetDlgItem(hwnd, IDC_PORT_LIST); 00695 00696 #ifdef _M_AMD64 00697 wsprintf(buffer, _T("0x%16I64x"), pDescriptor->u.Port.Start.QuadPart); 00698 #else 00699 wsprintf(buffer, _T("0x%08lx"), pDescriptor->u.Port.Start.u.LowPart); 00700 #endif 00701 00702 item.mask = LVIF_TEXT | LVIF_PARAM; 00703 item.iItem = 1000; 00704 item.iSubItem = 0; 00705 item.state = 0; 00706 item.stateMask = 0; 00707 item.pszText = buffer; 00708 item.cchTextMax = (int)_tcslen(item.pszText); 00709 item.lParam = (LPARAM)pDescriptor; 00710 00711 iItem = ListView_InsertItem(hwndLV, &item); 00712 if (iItem != -1) 00713 { 00714 wsprintf(buffer, _T("0x%lx"), pDescriptor->u.Port.Length); 00715 ListView_SetItemText(hwndLV, iItem, 1, buffer); 00716 00717 if (pDescriptor->Flags & CM_RESOURCE_PORT_IO) 00718 LoadString(hInst, IDS_PORT_PORT_IO, buffer, sizeof(buffer)/sizeof(TCHAR)); 00719 else 00720 LoadString(hInst, IDS_PORT_MEMORY_IO, buffer, sizeof(buffer)/sizeof(TCHAR)); 00721 ListView_SetItemText(hwndLV, iItem, 2, buffer); 00722 } 00723 break; 00724 00725 case CmResourceTypeInterrupt: 00726 hwndLV = GetDlgItem(hwnd, IDC_IRQ_LIST); 00727 00728 wsprintf(buffer, _T("%lu"), pDescriptor->u.Interrupt.Vector); 00729 00730 item.mask = LVIF_TEXT | LVIF_PARAM; 00731 item.iItem = 1000; 00732 item.iSubItem = 0; 00733 item.state = 0; 00734 item.stateMask = 0; 00735 item.pszText = buffer; 00736 item.cchTextMax = (int)_tcslen(item.pszText); 00737 item.lParam = (LPARAM)pDescriptor; 00738 00739 iItem = ListView_InsertItem(hwndLV, &item); 00740 if (iItem != -1) 00741 { 00742 wsprintf(buffer, _T("%lu"), pDescriptor->u.Interrupt.Level); 00743 ListView_SetItemText(hwndLV, iItem, 1, buffer); 00744 00745 wsprintf(buffer, _T("0x%08lx"), pDescriptor->u.Interrupt.Affinity); 00746 ListView_SetItemText(hwndLV, iItem, 2, buffer); 00747 00748 if (pDescriptor->Flags & CM_RESOURCE_INTERRUPT_LATCHED) 00749 LoadString(hInst, IDS_INTERRUPT_EDGE_SENSITIVE, buffer, sizeof(buffer)/sizeof(TCHAR)); 00750 else 00751 LoadString(hInst, IDS_INTERRUPT_LEVEL_SENSITIVE, buffer, sizeof(buffer)/sizeof(TCHAR)); 00752 00753 ListView_SetItemText(hwndLV, iItem, 3, buffer); 00754 } 00755 break; 00756 00757 case CmResourceTypeMemory: 00758 hwndLV = GetDlgItem(hwnd, IDC_MEMORY_LIST); 00759 00760 #ifdef _M_AMD64 00761 wsprintf(buffer, _T("0x%16I64x"), pDescriptor->u.Memory.Start.QuadPart); 00762 #else 00763 wsprintf(buffer, _T("0x%08lx"), pDescriptor->u.Memory.Start.u.LowPart); 00764 #endif 00765 00766 item.mask = LVIF_TEXT | LVIF_PARAM; 00767 item.iItem = 1000; 00768 item.iSubItem = 0; 00769 item.state = 0; 00770 item.stateMask = 0; 00771 item.pszText = buffer; 00772 item.cchTextMax = (int)_tcslen(item.pszText); 00773 item.lParam = (LPARAM)pDescriptor; 00774 00775 iItem = ListView_InsertItem(hwndLV, &item); 00776 if (iItem != -1) 00777 { 00778 wsprintf(buffer, _T("0x%lx"), pDescriptor->u.Memory.Length); 00779 ListView_SetItemText(hwndLV, iItem, 1, buffer); 00780 00781 switch (pDescriptor->Flags & (CM_RESOURCE_MEMORY_READ_ONLY | CM_RESOURCE_MEMORY_WRITE_ONLY)) 00782 { 00783 case CM_RESOURCE_MEMORY_READ_ONLY: 00784 LoadString(hInst, IDS_MEMORY_READ_ONLY, buffer, sizeof(buffer)/sizeof(TCHAR)); 00785 break; 00786 00787 case CM_RESOURCE_MEMORY_WRITE_ONLY: 00788 LoadString(hInst, IDS_MEMORY_WRITE_ONLY, buffer, sizeof(buffer)/sizeof(TCHAR)); 00789 break; 00790 00791 default: 00792 LoadString(hInst, IDS_MEMORY_READ_WRITE, buffer, sizeof(buffer)/sizeof(TCHAR)); 00793 break; 00794 } 00795 00796 ListView_SetItemText(hwndLV, iItem, 2, buffer); 00797 } 00798 break; 00799 00800 case CmResourceTypeDma: 00801 hwndLV = GetDlgItem(hwnd, IDC_DMA_LIST); 00802 00803 wsprintf(buffer, _T("%lu"), pDescriptor->u.Dma.Channel); 00804 00805 item.mask = LVIF_TEXT | LVIF_PARAM; 00806 item.iItem = 1000; 00807 item.iSubItem = 0; 00808 item.state = 0; 00809 item.stateMask = 0; 00810 item.pszText = buffer; 00811 item.cchTextMax = (int)_tcslen(item.pszText); 00812 item.lParam = (LPARAM)pDescriptor; 00813 00814 iItem = ListView_InsertItem(hwndLV, &item); 00815 if (iItem != -1) 00816 { 00817 wsprintf(buffer, _T("%lu"), pDescriptor->u.Dma.Port); 00818 ListView_SetItemText(hwndLV, iItem, 1, buffer); 00819 } 00820 break; 00821 00822 case CmResourceTypeDeviceSpecific: 00823 hwndLV = GetDlgItem(hwnd, IDC_DEVICE_LIST); 00824 00825 wsprintf(buffer, _T("0x%08lx"), pDescriptor->u.DeviceSpecificData.Reserved1); 00826 00827 item.mask = LVIF_TEXT | LVIF_PARAM; 00828 item.iItem = 1000; 00829 item.iSubItem = 0; 00830 item.state = 0; 00831 item.stateMask = 0; 00832 item.pszText = buffer; 00833 item.cchTextMax = (int)_tcslen(item.pszText); 00834 item.lParam = (LPARAM)pDescriptor; 00835 00836 iItem = ListView_InsertItem(hwndLV, &item); 00837 if (iItem != -1) 00838 { 00839 wsprintf(buffer, _T("0x%08lx"), pDescriptor->u.DeviceSpecificData.Reserved2); 00840 ListView_SetItemText(hwndLV, iItem, 1, buffer); 00841 00842 wsprintf(buffer, _T("0x%lx"), pDescriptor->u.DeviceSpecificData.DataSize); 00843 ListView_SetItemText(hwndLV, iItem, 2, buffer); 00844 } 00845 break; 00846 } 00847 } 00848 } 00849 00850 00851 static BOOL 00852 OnResourceNotify(HWND hwndDlg, NMHDR *phdr) 00853 { 00854 LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)phdr; 00855 00856 switch (phdr->idFrom) 00857 { 00858 case IDC_PORT_LIST: 00859 case IDC_MEMORY_LIST: 00860 case IDC_DMA_LIST: 00861 case IDC_IRQ_LIST: 00862 case IDC_DEVICE_LIST: 00863 switch(phdr->code) 00864 { 00865 case NM_CLICK: 00866 if (lpnmlv->iItem != -1) 00867 { 00868 PCM_PARTIAL_RESOURCE_DESCRIPTOR pDescriptor; 00869 LVITEM item; 00870 00871 item.mask = LVIF_PARAM; 00872 item.iItem = lpnmlv->iItem; 00873 item.iSubItem = 0; 00874 00875 if (ListView_GetItem(phdr->hwndFrom, &item)) 00876 { 00877 pDescriptor = (PCM_PARTIAL_RESOURCE_DESCRIPTOR)item.lParam; 00878 00879 EnableWindow(GetDlgItem(hwndDlg, IDC_UNDETERMINED), 00880 (pDescriptor->ShareDisposition == CmResourceShareUndetermined)); 00881 00882 EnableWindow(GetDlgItem(hwndDlg, IDC_SHARED), 00883 (pDescriptor->ShareDisposition == CmResourceShareShared)); 00884 00885 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_EXCLUSIVE), 00886 (pDescriptor->ShareDisposition == CmResourceShareDeviceExclusive)); 00887 00888 EnableWindow(GetDlgItem(hwndDlg, IDC_DRIVER_EXCLUSIVE), 00889 (pDescriptor->ShareDisposition == CmResourceShareDriverExclusive)); 00890 } 00891 } 00892 else 00893 { 00894 EnableWindow(GetDlgItem(hwndDlg, IDC_UNDETERMINED), FALSE); 00895 EnableWindow(GetDlgItem(hwndDlg, IDC_SHARED), FALSE); 00896 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_EXCLUSIVE), FALSE); 00897 EnableWindow(GetDlgItem(hwndDlg, IDC_DRIVER_EXCLUSIVE), FALSE); 00898 } 00899 break; 00900 } 00901 break; 00902 } 00903 00904 return FALSE; 00905 } 00906 00907 00908 static INT_PTR CALLBACK modify_resource_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 00909 { 00910 UNREFERENCED_PARAMETER(lParam); 00911 00912 switch(uMsg) 00913 { 00914 case WM_INITDIALOG: 00915 CreateResourceColumns(hwndDlg); 00916 ParseResources(hwndDlg); 00917 return FALSE; 00918 00919 case WM_NOTIFY: 00920 return OnResourceNotify(hwndDlg, (NMHDR *)lParam); 00921 00922 case WM_COMMAND: 00923 switch (LOWORD(wParam)) 00924 { 00925 case IDOK: 00926 EndDialog(hwndDlg, IDOK); 00927 break; 00928 case IDCANCEL: 00929 EndDialog(hwndDlg, IDCANCEL); 00930 return TRUE; 00931 } 00932 } 00933 return FALSE; 00934 } 00935 00936 static BOOL CreateResourceListColumns(HWND hWndListView) 00937 { 00938 TCHAR szText[80]; 00939 RECT rc; 00940 LV_COLUMN lvC; 00941 00942 ListView_SetExtendedListViewStyle(hWndListView, LVS_EX_FULLROWSELECT); 00943 00944 GetClientRect(hWndListView, &rc); 00945 00946 /* Create columns. */ 00947 lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; 00948 lvC.pszText = szText; 00949 lvC.fmt = LVCFMT_LEFT; 00950 00951 /* Load the column labels from the resource file. */ 00952 lvC.iSubItem = 0; 00953 lvC.cx = (rc.right - rc.left) / 2; 00954 LoadString(hInst, IDS_BUSNUMBER, szText, sizeof(szText)/sizeof(TCHAR)); 00955 if (ListView_InsertColumn(hWndListView, 0, &lvC) == -1) 00956 return FALSE; 00957 00958 lvC.iSubItem = 1; 00959 lvC.cx = (rc.right - rc.left) - lvC.cx; 00960 LoadString(hInst, IDS_INTERFACE, szText, sizeof(szText)/sizeof(TCHAR)); 00961 if (ListView_InsertColumn(hWndListView, 1, &lvC) == -1) 00962 return FALSE; 00963 00964 return TRUE; 00965 } 00966 00967 static VOID AddFullResourcesToList(HWND hwnd) 00968 { 00969 PCM_FULL_RESOURCE_DESCRIPTOR pFullDescriptor; 00970 TCHAR buffer[80]; 00971 LVITEM item; 00972 ULONG i; 00973 INT iItem; 00974 00975 for (i = 0; i < resourceValueData->Count; i++) 00976 { 00977 pFullDescriptor = &resourceValueData->List[i]; 00978 00979 wsprintf(buffer, _T("%lu"), pFullDescriptor->BusNumber); 00980 00981 item.mask = LVIF_TEXT; 00982 item.iItem = i; 00983 item.iSubItem = 0; 00984 item.state = 0; 00985 item.stateMask = 0; 00986 item.pszText = buffer; 00987 item.cchTextMax = (int)_tcslen(item.pszText); 00988 00989 iItem = ListView_InsertItem(hwnd, &item); 00990 if (iItem != -1) 00991 { 00992 GetInterfaceType(pFullDescriptor->InterfaceType, buffer, 80); 00993 ListView_SetItemText(hwnd, iItem, 1, buffer); 00994 } 00995 } 00996 } 00997 00998 static BOOL 00999 OnResourceListNotify(HWND hwndDlg, NMHDR *phdr) 01000 { 01001 LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)phdr; 01002 01003 switch (phdr->idFrom) 01004 { 01005 case IDC_RESOURCE_LIST: 01006 switch(phdr->code) 01007 { 01008 case NM_CLICK: 01009 fullResourceIndex = lpnmlv->iItem; 01010 EnableWindow(GetDlgItem(hwndDlg, IDC_SHOW_RESOURCE), (lpnmlv->iItem != -1)); 01011 break; 01012 01013 case NM_DBLCLK: 01014 if (lpnmlv->iItem != -1) 01015 { 01016 fullResourceIndex = lpnmlv->iItem; 01017 DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_RESOURCE), hwndDlg, modify_resource_dlgproc); 01018 } 01019 break; 01020 } 01021 break; 01022 } 01023 01024 return FALSE; 01025 } 01026 01027 01028 static INT_PTR CALLBACK modify_resource_list_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) 01029 { 01030 UNREFERENCED_PARAMETER(lParam); 01031 01032 switch(uMsg) 01033 { 01034 case WM_INITDIALOG: 01035 CreateResourceListColumns(GetDlgItem(hwndDlg, IDC_RESOURCE_LIST)); 01036 AddFullResourcesToList(GetDlgItem(hwndDlg, IDC_RESOURCE_LIST)); 01037 return FALSE; 01038 01039 case WM_NOTIFY: 01040 return OnResourceListNotify(hwndDlg, (NMHDR *)lParam); 01041 01042 case WM_COMMAND: 01043 switch (LOWORD(wParam)) 01044 { 01045 case IDC_SHOW_RESOURCE: 01046 if (fullResourceIndex != -1) 01047 DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_RESOURCE), hwndDlg, modify_resource_dlgproc); 01048 break; 01049 case IDOK: 01050 EndDialog(hwndDlg, IDOK); 01051 break; 01052 case IDCANCEL: 01053 EndDialog(hwndDlg, IDCANCEL); 01054 return TRUE; 01055 } 01056 } 01057 return FALSE; 01058 } 01059 01060 01061 BOOL ModifyValue(HWND hwnd, HKEY hKey, LPCTSTR valueName, BOOL EditBin) 01062 { 01063 DWORD type; 01064 LONG lRet; 01065 BOOL result = FALSE; 01066 01067 if (!hKey) 01068 return FALSE; 01069 01070 editValueName = valueName; 01071 01072 lRet = RegQueryValueEx(hKey, valueName, 0, &type, 0, &valueDataLen); 01073 if (lRet != ERROR_SUCCESS && (!_tcscmp(valueName, _T("")) || valueName == NULL)) 01074 { 01075 lRet = ERROR_SUCCESS; /* Allow editing of (Default) values which don't exist */ 01076 type = REG_SZ; 01077 valueDataLen = 0; 01078 stringValueData = NULL; 01079 binValueData = NULL; 01080 } 01081 01082 if (lRet != ERROR_SUCCESS) 01083 { 01084 error(hwnd, IDS_BAD_VALUE, valueName); 01085 goto done; 01086 } 01087 01088 if (EditBin == FALSE && ((type == REG_SZ) || (type == REG_EXPAND_SZ))) 01089 { 01090 if (valueDataLen > 0) 01091 { 01092 if (!(stringValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen))) 01093 { 01094 error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); 01095 goto done; 01096 } 01097 lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)stringValueData, &valueDataLen); 01098 if (lRet != ERROR_SUCCESS) 01099 { 01100 error(hwnd, IDS_BAD_VALUE, valueName); 01101 goto done; 01102 } 01103 } 01104 else 01105 { 01106 stringValueData = NULL; 01107 } 01108 01109 if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_STRING), hwnd, modify_string_dlgproc) == IDOK) 01110 { 01111 if (stringValueData) 01112 { 01113 lRet = RegSetValueEx(hKey, valueName, 0, type, (LPBYTE)stringValueData, (DWORD) (_tcslen(stringValueData) + 1) * sizeof(TCHAR)); 01114 } 01115 else 01116 { 01117 lRet = RegSetValueEx(hKey, valueName, 0, type, NULL, 0); 01118 } 01119 if (lRet == ERROR_SUCCESS) 01120 result = TRUE; 01121 } 01122 } 01123 else if (EditBin == FALSE && type == REG_MULTI_SZ) 01124 { 01125 if (valueDataLen > 0) 01126 { 01127 size_t llen, listlen, nl_len; 01128 LPTSTR src, lines = NULL; 01129 01130 if (!(stringValueData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, valueDataLen + sizeof(TCHAR)))) 01131 { 01132 error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); 01133 goto done; 01134 } 01135 lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)stringValueData, &valueDataLen); 01136 if (lRet != ERROR_SUCCESS) 01137 { 01138 error(hwnd, IDS_BAD_VALUE, valueName); 01139 goto done; 01140 } 01141 01142 /* convert \0 to \r\n */ 01143 src = stringValueData; 01144 nl_len = _tcslen(_T("\r\n")) * sizeof(TCHAR); 01145 listlen = sizeof(TCHAR); 01146 lines = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, listlen + sizeof(TCHAR)); 01147 while(*src != _T('\0')) 01148 { 01149 llen = _tcslen(src); 01150 if(llen == 0) 01151 break; 01152 listlen += (llen * sizeof(TCHAR)) + nl_len; 01153 lines = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lines, listlen); 01154 _tcscat(lines, src); 01155 _tcscat(lines, _T("\r\n")); 01156 src += llen + 1; 01157 } 01158 HeapFree(GetProcessHeap(), 0, stringValueData); 01159 stringValueData = lines; 01160 } 01161 else 01162 { 01163 stringValueData = NULL; 01164 } 01165 01166 if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_MULTI_STRING), hwnd, modify_multi_string_dlgproc) == IDOK) 01167 { 01168 if (stringValueData) 01169 { 01170 /* convert \r\n to \0 */ 01171 BOOL EmptyLines = FALSE; 01172 LPTSTR src, lines, nl; 01173 size_t linechars, buflen, c_nl, dest; 01174 01175 src = stringValueData; 01176 buflen = sizeof(TCHAR); 01177 lines = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buflen + sizeof(TCHAR)); 01178 c_nl = _tcslen(_T("\r\n")); 01179 dest = 0; 01180 while(*src != _T('\0')) 01181 { 01182 if((nl = _tcsstr(src, _T("\r\n")))) 01183 { 01184 linechars = nl - src; 01185 if(nl == src) 01186 { 01187 EmptyLines = TRUE; 01188 src = nl + c_nl; 01189 continue; 01190 } 01191 } 01192 else 01193 { 01194 linechars = _tcslen(src); 01195 } 01196 if(linechars > 0) 01197 { 01198 buflen += ((linechars + 1) * sizeof(TCHAR)); 01199 lines = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, lines, buflen); 01200 memcpy((lines + dest), src, linechars * sizeof(TCHAR)); 01201 dest += linechars; 01202 lines[dest++] = _T('\0'); 01203 } 01204 else 01205 { 01206 EmptyLines = TRUE; 01207 } 01208 src += linechars + (nl != NULL ? c_nl : 0); 01209 } 01210 lines[++dest] = _T('\0'); 01211 01212 if(EmptyLines) 01213 { 01214 warning(hwnd, IDS_MULTI_SZ_EMPTY_STRING); 01215 } 01216 01217 lRet = RegSetValueEx(hKey, valueName, 0, type, (LPBYTE)lines, (DWORD) buflen); 01218 HeapFree(GetProcessHeap(), 0, lines); 01219 } 01220 else 01221 { 01222 lRet = RegSetValueEx(hKey, valueName, 0, type, NULL, 0); 01223 } 01224 if (lRet == ERROR_SUCCESS) 01225 result = TRUE; 01226 } 01227 } 01228 else if (EditBin == FALSE && type == REG_DWORD) 01229 { 01230 lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)&dwordValueData, &valueDataLen); 01231 if (lRet != ERROR_SUCCESS) 01232 { 01233 error(hwnd, IDS_BAD_VALUE, valueName); 01234 goto done; 01235 } 01236 01237 if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_DWORD), hwnd, modify_dword_dlgproc) == IDOK) 01238 { 01239 lRet = RegSetValueEx(hKey, valueName, 0, type, (LPBYTE)&dwordValueData, sizeof(DWORD)); 01240 if (lRet == ERROR_SUCCESS) 01241 result = TRUE; 01242 } 01243 } 01244 else if (EditBin == FALSE && type == REG_RESOURCE_LIST) 01245 { 01246 if (valueDataLen > 0) 01247 { 01248 resourceValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen); 01249 if (resourceValueData == NULL) 01250 { 01251 error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); 01252 goto done; 01253 } 01254 01255 lRet = RegQueryValueEx(hKey, valueName, 0, 0, (LPBYTE)resourceValueData, &valueDataLen); 01256 if (lRet != ERROR_SUCCESS) 01257 { 01258 error(hwnd, IDS_BAD_VALUE, valueName); 01259 goto done; 01260 } 01261 } 01262 else 01263 { 01264 resourceValueData = NULL; 01265 } 01266 01267 if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_RESOURCE_LIST), hwnd, modify_resource_list_dlgproc) == IDOK) 01268 { 01269 } 01270 } 01271 else if (EditBin == TRUE || type == REG_NONE || type == REG_BINARY) 01272 { 01273 #ifndef UNICODE 01274 LPWSTR u_valuename; 01275 int len_vname = lstrlen(valueName); 01276 01277 if(len_vname > 0) 01278 { 01279 if(!(u_valuename = HeapAlloc(GetProcessHeap(), 0, (len_vname + 1) * sizeof(WCHAR)))) 01280 { 01281 error(hwnd, IDS_TOO_BIG_VALUE, len_vname); 01282 goto done; 01283 } 01284 /* convert the ansi value name to an unicode string */ 01285 MultiByteToWideChar(CP_ACP, 0, valueName, -1, u_valuename, len_vname + 1); 01286 valueDataLen *= sizeof(WCHAR); 01287 } 01288 else 01289 u_valuename = L""; 01290 #endif 01291 if(valueDataLen > 0) 01292 { 01293 if(!(binValueData = HeapAlloc(GetProcessHeap(), 0, valueDataLen + 1))) 01294 { 01295 error(hwnd, IDS_TOO_BIG_VALUE, valueDataLen); 01296 goto done; 01297 } 01298 01299 /* force to use the unicode version, so editing strings in binary mode is correct */ 01300 lRet = RegQueryValueExW(hKey, 01301 #ifndef UNICODE 01302 u_valuename, 01303 #else 01304 valueName, 01305 #endif 01306 0, 0, (LPBYTE)binValueData, &valueDataLen); 01307 if (lRet != ERROR_SUCCESS) 01308 { 01309 HeapFree(GetProcessHeap(), 0, binValueData); 01310 #ifndef UNICODE 01311 if(len_vname > 0) 01312 HeapFree(GetProcessHeap(), 0, u_valuename); 01313 #endif 01314 error(hwnd, IDS_BAD_VALUE, valueName); 01315 goto done; 01316 } 01317 } 01318 else 01319 { 01320 binValueData = NULL; 01321 } 01322 01323 if (DialogBox(0, MAKEINTRESOURCE(IDD_EDIT_BIN_DATA), hwnd, modify_binary_dlgproc) == IDOK) 01324 { 01325 /* force to use the unicode version, so editing strings in binary mode is correct */ 01326 lRet = RegSetValueExW(hKey, 01327 #ifndef UNICODE 01328 u_valuename, 01329 #else 01330 valueName, 01331 #endif 01332 0, type, (LPBYTE)binValueData, valueDataLen); 01333 if (lRet == ERROR_SUCCESS) 01334 result = TRUE; 01335 } 01336 if(binValueData != NULL) 01337 HeapFree(GetProcessHeap(), 0, binValueData); 01338 #ifndef UNICODE 01339 if(len_vname > 0) 01340 HeapFree(GetProcessHeap(), 0, u_valuename); 01341 #endif 01342 } 01343 else 01344 { 01345 error(hwnd, IDS_UNSUPPORTED_TYPE, type); 01346 } 01347 01348 done: 01349 if (resourceValueData) 01350 HeapFree(GetProcessHeap(), 0, resourceValueData); 01351 resourceValueData = NULL; 01352 01353 if (stringValueData) 01354 HeapFree(GetProcessHeap(), 0, stringValueData); 01355 stringValueData = NULL; 01356 01357 return result; 01358 } 01359 01360 static LONG CopyKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrcSubKey) 01361 { 01362 LONG lResult; 01363 DWORD dwDisposition; 01364 HKEY hDestSubKey = NULL; 01365 HKEY hSrcSubKey = NULL; 01366 DWORD dwIndex, dwType, cbName, cbData; 01367 TCHAR szSubKey[256]; 01368 TCHAR szValueName[256]; 01369 BYTE szValueData[512]; 01370 01371 FILETIME ft; 01372 01373 /* open the source subkey, if specified */ 01374 if (lpSrcSubKey) 01375 { 01376 lResult = RegOpenKeyEx(hSrcKey, lpSrcSubKey, 0, KEY_ALL_ACCESS, &hSrcSubKey); 01377 if (lResult) 01378 goto done; 01379 hSrcKey = hSrcSubKey; 01380 } 01381 01382 /* create the destination subkey */ 01383 lResult = RegCreateKeyEx(hDestKey, lpDestSubKey, 0, NULL, 0, KEY_WRITE, NULL, 01384 &hDestSubKey, &dwDisposition); 01385 if (lResult) 01386 goto done; 01387 01388 /* copy all subkeys */ 01389 dwIndex = 0; 01390 do 01391 { 01392 cbName = sizeof(szSubKey) / sizeof(szSubKey[0]); 01393 lResult = RegEnumKeyEx(hSrcKey, dwIndex++, szSubKey, &cbName, NULL, NULL, NULL, &ft); 01394 if (lResult == ERROR_SUCCESS) 01395 { 01396 lResult = CopyKey(hDestSubKey, szSubKey, hSrcKey, szSubKey); 01397 if (lResult) 01398 goto done; 01399 } 01400 } 01401 while(lResult == ERROR_SUCCESS); 01402 01403 /* copy all subvalues */ 01404 dwIndex = 0; 01405 do 01406 { 01407 cbName = sizeof(szValueName) / sizeof(szValueName[0]); 01408 cbData = sizeof(szValueData) / sizeof(szValueData[0]); 01409 lResult = RegEnumValue(hSrcKey, dwIndex++, szValueName, &cbName, NULL, &dwType, szValueData, &cbData); 01410 if (lResult == ERROR_SUCCESS) 01411 { 01412 lResult = RegSetValueEx(hDestSubKey, szValueName, 0, dwType, szValueData, cbData); 01413 if (lResult) 01414 goto done; 01415 } 01416 } 01417 while(lResult == ERROR_SUCCESS); 01418 01419 lResult = ERROR_SUCCESS; 01420 01421 done: 01422 if (hSrcSubKey) 01423 RegCloseKey(hSrcSubKey); 01424 if (hDestSubKey) 01425 RegCloseKey(hDestSubKey); 01426 if (lResult != ERROR_SUCCESS) 01427 SHDeleteKey(hDestKey, lpDestSubKey); 01428 return lResult; 01429 } 01430 01431 static LONG MoveKey(HKEY hDestKey, LPCTSTR lpDestSubKey, HKEY hSrcKey, LPCTSTR lpSrcSubKey) 01432 { 01433 LONG lResult; 01434 01435 if (!lpSrcSubKey) 01436 return ERROR_INVALID_FUNCTION; 01437 01438 lResult = CopyKey(hDestKey, lpDestSubKey, hSrcKey, lpSrcSubKey); 01439 if (lResult == ERROR_SUCCESS) 01440 SHDeleteKey(hSrcKey, lpSrcSubKey); 01441 01442 return lResult; 01443 } 01444 01445 BOOL DeleteKey(HWND hwnd, HKEY hKeyRoot, LPCTSTR keyPath) 01446 { 01447 TCHAR msg[128], caption[128]; 01448 BOOL result = FALSE; 01449 LONG lRet; 01450 HKEY hKey; 01451 01452 lRet = RegOpenKeyEx(hKeyRoot, keyPath, 0, KEY_READ|KEY_SET_VALUE, &hKey); 01453 if (lRet != ERROR_SUCCESS) 01454 { 01455 error_code_messagebox(hwnd, lRet); 01456 return FALSE; 01457 } 01458 01459 LoadString(hInst, IDS_QUERY_DELETE_KEY_CONFIRM, caption, sizeof(caption)/sizeof(TCHAR)); 01460 LoadString(hInst, IDS_QUERY_DELETE_KEY_ONE, msg, sizeof(msg)/sizeof(TCHAR)); 01461 01462 if (MessageBox(g_pChildWnd->hWnd, msg, caption, MB_ICONQUESTION | MB_YESNO) != IDYES) 01463 goto done; 01464 01465 lRet = SHDeleteKey(hKeyRoot, keyPath); 01466 if (lRet != ERROR_SUCCESS) 01467 { 01468 error(hwnd, IDS_BAD_KEY, keyPath); 01469 goto done; 01470 } 01471 result = TRUE; 01472 01473 done: 01474 RegCloseKey(hKey); 01475 return result; 01476 } 01477 01478 LONG RenameKey(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpNewName) 01479 { 01480 LPCTSTR s; 01481 LPTSTR lpNewSubKey = NULL; 01482 LONG Ret = 0; 01483 01484 if (!lpSubKey) 01485 return Ret; 01486 01487 s = _tcsrchr(lpSubKey, _T('\\')); 01488 if (s) 01489 { 01490 s++; 01491 lpNewSubKey = (LPTSTR) HeapAlloc(GetProcessHeap(), 0, (s - lpSubKey + _tcslen(lpNewName) + 1) * sizeof(TCHAR)); 01492 if (lpNewSubKey != NULL) 01493 { 01494 memcpy(lpNewSubKey, lpSubKey, (s - lpSubKey) * sizeof(TCHAR)); 01495 lstrcpy(lpNewSubKey + (s - lpSubKey), lpNewName); 01496 lpNewName = lpNewSubKey; 01497 } 01498 else 01499 return ERROR_NOT_ENOUGH_MEMORY; 01500 } 01501 01502 Ret = MoveKey(hKey, lpNewName, hKey, lpSubKey); 01503 01504 if (lpNewSubKey) 01505 { 01506 HeapFree(GetProcessHeap(), 0, lpNewSubKey); 01507 } 01508 return Ret; 01509 } 01510 01511 LONG RenameValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpDestValue, LPCTSTR lpSrcValue) 01512 { 01513 LONG lResult; 01514 HKEY hSubKey = NULL; 01515 DWORD dwType, cbData; 01516 BYTE data[512]; 01517 01518 if (lpSubKey) 01519 { 01520 lResult = RegOpenKey(hKey, lpSubKey, &hSubKey); 01521 if (lResult != ERROR_SUCCESS) 01522 goto done; 01523 hKey = hSubKey; 01524 } 01525 01526 cbData = sizeof(data); 01527 lResult = RegQueryValueEx(hKey, lpSrcValue, NULL, &dwType, data, &cbData); 01528 if (lResult != ERROR_SUCCESS) 01529 goto done; 01530 01531 lResult = RegSetValueEx(hKey, lpDestValue, 0, dwType, data, cbData); 01532 if (lResult != ERROR_SUCCESS) 01533 goto done; 01534 01535 RegDeleteValue(hKey, lpSrcValue); 01536 01537 done: 01538 if (hSubKey) 01539 RegCloseKey(hSubKey); 01540 return lResult; 01541 } 01542 01543 LONG QueryStringValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPTSTR pszBuffer, DWORD dwBufferLen) 01544 { 01545 LONG lResult; 01546 HKEY hSubKey = NULL; 01547 DWORD cbData, dwType; 01548 01549 if (lpSubKey) 01550 { 01551 lResult = RegOpenKey(hKey, lpSubKey, &hSubKey); 01552 if (lResult != ERROR_SUCCESS) 01553 goto done; 01554 hKey = hSubKey; 01555 } 01556 01557 cbData = (dwBufferLen - 1) * sizeof(*pszBuffer); 01558 lResult = RegQueryValueEx(hKey, lpValueName, NULL, &dwType, (LPBYTE) pszBuffer, &cbData); 01559 if (lResult != ERROR_SUCCESS) 01560 goto done; 01561 if (dwType != REG_SZ) 01562 { 01563 lResult = -1; 01564 goto done; 01565 } 01566 01567 pszBuffer[cbData / sizeof(*pszBuffer)] = _T('\0'); 01568 01569 done: 01570 if (lResult != ERROR_SUCCESS) 01571 pszBuffer[0] = _T('\0'); 01572 if (hSubKey) 01573 RegCloseKey(hSubKey); 01574 return lResult; 01575 } 01576 01577 BOOL GetKeyName(LPTSTR pszDest, size_t iDestLength, HKEY hRootKey, LPCTSTR lpSubKey) 01578 { 01579 LPCTSTR pszRootKey; 01580 01581 if (hRootKey == HKEY_CLASSES_ROOT) 01582 pszRootKey = TEXT("HKEY_CLASSES_ROOT"); 01583 else if (hRootKey == HKEY_CURRENT_USER) 01584 pszRootKey = TEXT("HKEY_CURRENT_USER"); 01585 else if (hRootKey == HKEY_LOCAL_MACHINE) 01586 pszRootKey = TEXT("HKEY_LOCAL_MACHINE"); 01587 else if (hRootKey == HKEY_USERS) 01588 pszRootKey = TEXT("HKEY_USERS"); 01589 else if (hRootKey == HKEY_CURRENT_CONFIG) 01590 pszRootKey = TEXT("HKEY_CURRENT_CONFIG"); 01591 else if (hRootKey == HKEY_DYN_DATA) 01592 pszRootKey = TEXT("HKEY_DYN_DATA"); 01593 else 01594 return FALSE; 01595 01596 if (lpSubKey[0]) 01597 _sntprintf(pszDest, iDestLength, TEXT("%s\\%s"), pszRootKey, lpSubKey); 01598 else 01599 _sntprintf(pszDest, iDestLength, TEXT("%s"), pszRootKey); 01600 return TRUE; 01601 } Generated on Fri May 25 2012 04:15:45 for ReactOS by
1.7.6.1
|