NTSTATUS UpdateCheckSilentThread( _In_ PVOID Parameter ) { PPH_UPDATER_CONTEXT context = NULL; ULONGLONG currentVersion = 0; ULONGLONG latestVersion = 0; context = CreateUpdateContext(TRUE); #ifndef FORCE_UPDATE_CHECK if (!LastUpdateCheckExpired()) goto CleanupExit; #endif Sleep(5 * 1000); // Clear the application cache directory. PhClearCacheDirectory(); // Query latest update information from the server. if (!QueryUpdateData(context)) goto CleanupExit; currentVersion = ParseVersionString(context->CurrentVersionString); #ifdef FORCE_UPDATE_CHECK latestVersion = MAKE_VERSION_ULONGLONG( 9999, 9999, 9999, 0 ); #else latestVersion = ParseVersionString(context->Version); #endif // Compare the current version against the latest available version if (currentVersion < latestVersion) { // Check if the user hasn't already opened the dialog. if (!UpdateDialogHandle) { // We have data we're going to cache and pass into the dialog context->HaveData = TRUE; // Show the dialog asynchronously on a new thread. ShowUpdateDialog(context); } } CleanupExit: if (!context->HaveData) FreeUpdateContext(context); return STATUS_SUCCESS; }
NTSTATUS UpdateCheckThread( _In_ PVOID Parameter ) { PPH_UPDATER_CONTEXT context = NULL; ULONGLONG currentVersion = 0; ULONGLONG latestVersion = 0; context = (PPH_UPDATER_CONTEXT)Parameter; context->ErrorCode = STATUS_SUCCESS; // Check if we have cached update data if (!context->HaveData) { context->HaveData = QueryUpdateData(context); } if (!context->HaveData) { ShowUpdateFailedDialog(context, FALSE, FALSE); PhDereferenceObject(context); return STATUS_SUCCESS; } currentVersion = ParseVersionString(context->CurrentVersionString); #ifdef FORCE_UPDATE_CHECK latestVersion = MAKE_VERSION_ULONGLONG( 9999, 9999, 9999, 0 ); #else latestVersion = ParseVersionString(context->Version); #endif if (currentVersion == latestVersion) { // User is running the latest version ShowLatestVersionDialog(context); } else if (currentVersion > latestVersion) { // User is running a newer version ShowNewerVersionDialog(context); } else { // User is running an older version ShowAvailableDialog(context); } PhDereferenceObject(context); return STATUS_SUCCESS; }
/*************************************************************************** Function: CheckFileVersion Purpose: Check the version information of a given file Input: File name File location (Windows dir, System dir, Current dir or none) Reference to Major number Reference to Minor number Reference to Build number Output: TRUE only if successful Remarks: Trashes original file name ****************************************************************************/ BOOL CDLLVersion::CheckFileVersion (LPSTR szFileName, DWORD &dwMajor, DWORD &dwMinor, DWORD &dwRelease, DWORD &dwBuildNumber) { LPSTR lpVersion; // String pointer to 'version' text UINT uVersionLen; DWORD dwVerHnd=0; // An 'ignored' parameter, always '0' //FixFilePath (szFileName); // Add necessary path prefix to file name DWORD dwVerInfoSize = GetFileVersionInfoSize (szFileName, &dwVerHnd); if (!dwVerInfoSize) // Cannot reach the DLL file return FALSE; LPSTR lpstrVffInfo = (LPSTR) malloc (dwVerInfoSize); // Alloc memory for file info if (lpstrVffInfo == NULL) return FALSE; // Allocation failed // Try to get the info if (!GetFileVersionInfo(szFileName, dwVerHnd, dwVerInfoSize, lpstrVffInfo)) { free (lpstrVffInfo); return FALSE; // Cannot read the file information - // wierd, since we could read the information size } LANGANDCODEPAGE *lpTranslate; char szFileVersion[MAX_PATH]; UINT cbTranslate; VerQueryValue(lpstrVffInfo, TEXT("\\VarFileInfo\\Translation"), (LPVOID*)&lpTranslate, &cbTranslate); sprintf(szFileVersion, "\\StringFileInfo\\%04x%04x\\FileVersion", lpTranslate[0].wLanguage, lpTranslate[0].wCodePage); if (!VerQueryValue ( lpstrVffInfo, (LPSTR) (TEXT(szFileVersion)), (LPVOID *)&lpVersion, (UINT *)&uVersionLen)) { free (lpstrVffInfo); return FALSE; // Query was unsuccessful } // Now we have a string that looks like this : // "MajorVersion.MinorVersion.BuildNumber", so let's parse it BOOL bRes = ParseVersionString (lpVersion, dwMajor, dwMinor, dwRelease, dwBuildNumber, ","); if (!bRes) { bRes = ParseVersionString (lpVersion, dwMajor, dwMinor, dwRelease, dwBuildNumber, "."); } free (lpstrVffInfo); return bRes; }
//HeaderString void NifStream( HeaderString & val, istream& in, NifInfo & info ) { char tmp[256]; in.getline( tmp, 256 ); val.header = tmp; // make sure this is a NIF file unsigned ver_start = 0; if ( val.header.substr(0, 22) == "NetImmerse File Format" ) { ver_start = 32; } else if ( val.header.substr(0, 20) == "Gamebryo File Format" ) { ver_start = 30; } else if ( val.header.substr(0, 6) == "NDSNIF" ) { ver_start = 30; } else { //Not a NIF file info.version = VER_INVALID; } //Parse version string and return result. info.version = ParseVersionString( val.header.substr( ver_start ) ); ////Temporarily read the next 3 strings if this is a < 4 file //if ( info.version < VER_3_3_0_13 ) { // in.getline( tmp, 256 ); // in.getline( tmp, 256 ); // in.getline( tmp, 256 ); //} //if ( version < VER_4_0_0_0 ) { // throw runtime_error("NIF Versions below 4.0.0.0 are not yet supported"); //} };
NTSTATUS SetupDownloadWebSetupThread( _In_ PPH_SETUP_CONTEXT Context ) { ULONGLONG currentVersion = 0; ULONGLONG latestVersion = 0; PPH_STRING setupFileName; PH_IMAGE_VERSION_INFO versionInfo; if (!SetupQueryUpdateData(Context)) goto CleanupExit; setupFileName = PhGetApplicationFileName(); if (!PhInitializeImageVersionInfo(&versionInfo, PhGetString(setupFileName))) goto CleanupExit; currentVersion = ParseVersionString(versionInfo.FileVersion); #ifdef FORCE_UPDATE_CHECK latestVersion = MAKE_VERSION_ULONGLONG( 9999, 9999, 9999, 0 ); #else latestVersion = ParseVersionString(Context->WebSetupFileVersion); #endif // Compare the current version against the latest available version if (currentVersion < latestVersion) { if (!UpdateDownloadUpdateData(Context)) goto CleanupExit; } PostMessage(Context->DialogHandle, PSM_SETCURSELID, 0, IDD_DIALOG5); return STATUS_SUCCESS; CleanupExit: PostMessage(Context->DialogHandle, PSM_SETCURSELID, 0, IDD_ERROR); return STATUS_FAIL_CHECK; }
LRESULT CALLBACK StringTableDrawProc(HWND hwnd, UINT iMessage, WPARAM wParam, LPARAM lParam) { static HCURSOR origCurs; RECT r; LPCREATESTRUCT createStruct; struct resRes *stringTableData; LVHITTESTINFO hittest; int i; struct stringTableUndo *undo; switch (iMessage) { case WM_MDIACTIVATE: if ((HWND)lParam == hwnd) { doMaximize(); } break; case WM_SETFOCUS: stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); SetFocus(stringTableData->gd.childWindow); break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case LVN_GETDISPINFO: { LV_DISPINFO *plvdi = (LV_DISPINFO*)lParam; STRINGS *strings; plvdi->item.mask |= LVIF_TEXT | LVIF_DI_SETITEM; plvdi->item.mask &= ~LVIF_IMAGE; strings = (STRINGS *)plvdi->item.lParam; switch (plvdi->item.iSubItem) { char id[256]; case 1: FormatVersionString(id, strings->string, strings->length);//FIXME id plvdi->item.pszText = id; break; } break; } case LVN_KEYDOWN: { stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(ID_EDIT, CBN_KILLFOCUS), 0); switch (((LPNMLVKEYDOWN)lParam)->wVKey) { case 'S': if (GetKeyState(VK_CONTROL) &0x80000000) { PostMessage(hwnd, WM_COMMAND, IDM_SAVE, 0); return TRUE; } break; case 'Z': if (GetKeyState(VK_CONTROL) &0x80000000) { PostMessage(hwnd, WM_COMMAND, IDM_UNDO, 0); return TRUE; } break; case VK_INSERT: stringTableData->gd.selectedRow = ListView_GetNextItem(stringTableData->gd.childWindow, -1, LVNI_SELECTED); PostMessage(hwnd, WM_COMMAND, IDM_INSERT, 0); return TRUE; case VK_DELETE: stringTableData->gd.selectedRow = ListView_GetNextItem(stringTableData->gd.childWindow, -1, LVNI_SELECTED); PostMessage(hwnd, WM_COMMAND, IDM_DELETE, 0); return TRUE; } } break; case NM_CLICK: { SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(ID_EDIT, CBN_KILLFOCUS), 0); } break; case NM_RCLICK: { POINT pt; stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); GetCursorPos(&hittest.pt); pt = hittest.pt; ScreenToClient(stringTableData->gd.childWindow, &hittest.pt); if (ListView_HitTest(stringTableData->gd.childWindow, &hittest) < 0) { hittest.iItem = ListView_GetItemCount(stringTableData->gd.childWindow); hittest.iSubItem = 0; } { HMENU menu, popup; SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(ID_EDIT, CBN_KILLFOCUS), 0); menu = LoadMenuGeneric(hInstance, "RESSTRINGSMENU"); stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); stringTableData->gd.selectedRow = hittest.iItem; stringTableData->gd.selectedColumn = hittest.iSubItem; popup = GetSubMenu(menu, 0); InsertBitmapsInMenu(popup); TrackPopupMenuEx(popup, TPM_TOPALIGN | TPM_LEFTALIGN | TPM_LEFTBUTTON, pt.x, pt.y, hwnd, NULL); DestroyMenu(menu); } return 1; } break; case NM_DBLCLK: stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); GetCursorPos(&hittest.pt); ScreenToClient(stringTableData->gd.childWindow, &hittest.pt); if (ListView_SubItemHitTest(stringTableData->gd.childWindow, &hittest) >= 0) { stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); stringTableData->gd.selectedRow = hittest.iItem; stringTableData->gd.selectedColumn = hittest.iSubItem; PostMessage(hwnd, WM_HANDLEDBLCLICK, 0, 0); } break; case NM_SETFOCUS: stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); SetResourceProperties(stringTableData, &accFuncs); break; case NM_KILLFOCUS: // SetResourceProperties(NULL, NULL); break; } break; case WM_HANDLEDBLCLICK: { STRINGS *strings; RECT r; stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); if (stringTableData->gd.editWindow) { DestroyWindow(stringTableData->gd.editWindow); stringTableData->gd.editWindow = NULL; } strings = stringTableData->resource->u.stringtable; i = 0; while (strings && strings->next && i < stringTableData->gd.selectedRow) strings = strings->next, i++; if (strings) { ListView_GetSubItemRect(stringTableData->gd.childWindow, stringTableData->gd.selectedRow, stringTableData->gd.selectedColumn, LVIR_BOUNDS, &r); stringTableData->gd.editWindow = CreateWindow("edit", "", WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_BORDER, r.left,r.top,r.right-r.left,16, hwnd, (HMENU)ID_EDIT, hInstance, NULL); SetParent(stringTableData->gd.editWindow, stringTableData->gd.childWindow); AccSubclassEditWnd(hwnd, stringTableData->gd.editWindow); switch(stringTableData->gd.selectedColumn) { char buf[256]; case 0: buf[0] = 0; FormatExp(buf, strings->id); SendMessage(stringTableData->gd.editWindow, WM_SETTEXT, 0, (LPARAM)buf); break; case 1: FormatVersionString(buf, strings->string, strings->length); buf[strlen(buf)-1] = 0; SendMessage(stringTableData->gd.editWindow, WM_SETTEXT, 0, (LPARAM)buf+1); break; } SendMessage(stringTableData->gd.editWindow, EM_SETSEL, 0, -1); SetFocus(stringTableData->gd.editWindow); } } break; case WM_TIMER: stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); ListView_Scroll(stringTableData->gd.childWindow, 0, (stringTableData->gd.lvscroll & 1) ? -16 : 16); break; case WM_COMMAND: stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); switch (LOWORD(wParam)) { case ID_EDIT: if (HIWORD(wParam) == CBN_KILLFOCUS || HIWORD(wParam) == EN_KILLFOCUS) { static BOOL inKillFocus; if (stringTableData->gd.editWindow && !inKillFocus) { STRINGS *strings = stringTableData->resource->u.stringtable; i = 0; while (strings && strings->next && i < stringTableData->gd.selectedRow) strings = strings->next,i++; if (strings) { char buf[256]; buf[GetWindowText(stringTableData->gd.editWindow, buf, sizeof(buf)-1)] = 0; StringTableSetChanged(stringTableData, strings); if (stringTableData->gd.selectedColumn == 0) { PropSetIdName(stringTableData, buf, &strings->id, NULL); } else { int len; char *p = ParseVersionString(buf, &len); //FIXME ? strings->length = StringAsciiToWChar(&strings->string, p, len); ResGetStringItemName(strings->id, p); } ListView_DeleteItem(stringTableData->gd.childWindow, stringTableData->gd.selectedRow); PopulateItem(stringTableData->gd.childWindow, strings, stringTableData->gd.selectedRow); } i = 0; inKillFocus = TRUE; DestroyWindow(stringTableData->gd.editWindow); inKillFocus = FALSE; stringTableData->gd.editWindow = NULL; } } break; case IDM_INSERT: StringTableInsert(stringTableData, stringTableData->gd.selectedRow); break; case IDM_DELETE: StringTableDelete(stringTableData, stringTableData->gd.selectedRow); break; case IDM_SAVE: if (stringTableData->resource->changed) { ResSaveCurrent(workArea, stringTableData); } break; case IDM_UNDO: StringTableUndo(hwnd, stringTableData); break; } break; case EM_CANUNDO: stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); return stringTableData->gd.undoData != NULL; case WM_CREATE: GetClientRect(hwnd, &r); createStruct = (LPCREATESTRUCT)lParam; stringTableData = (struct resRes *)((LPMDICREATESTRUCT)(createStruct->lpCreateParams))->lParam; SetWindowLong(hwnd, 0, (long)stringTableData); stringTableData->activeHwnd = hwnd; stringTableData->gd.childWindow = CreateWindowEx(0, WC_LISTVIEW, "", WS_VISIBLE | WS_CHILD | LVS_REPORT | LVS_SINGLESEL, 0, 0, r.right, r.bottom, hwnd, (HMENU)ID_TREEVIEW, hInstance, NULL); SetListViewColumns(hwnd, stringTableData->gd.childWindow); PopulateStrings(hwnd, stringTableData ); break; case WM_CLOSE: SendMessage(hwndSrcTab, TABM_REMOVE, 0, (LPARAM)hwnd); break; case WM_DESTROY: stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); if (stringTableData->gd.editWindow) DestroyWindow(stringTableData->gd.editWindow); stringTableData->gd.editWindow = NULL; undo = stringTableData->gd.undoData; if (undo) stringTableData->gd.cantClearUndo = TRUE; while (undo) { struct stringTableUndo *next = undo->next; free(undo); undo = next; } stringTableData->gd.undoData = NULL; stringTableData->activeHwnd = NULL; break; case WM_SIZE: stringTableData = (struct resRes *)GetWindowLong(hwnd, 0); MoveWindow(stringTableData->gd.childWindow, 0, 0, LOWORD(lParam), HIWORD(lParam), 1); break; default: break; } return DefMDIChildProc(hwnd, iMessage, wParam, lParam); }
/*************************************************************************** Function: CheckFileVersion Purpose: Check the version information of a given file Input: File name File location (Windows dir, System dir, Current dir or none) Reference to Major number Reference to Minor number Reference to Build number Output: TRUE only if successful Remarks: Trashes original file name ****************************************************************************/ BOOL CDLLVersion::CheckFileVersion (LPSTR szFileName, int FileLoc, DWORD &dwMajor, DWORD &dwMinor, DWORD &dwBuildNumber) { LPSTR lpVersion; // String pointer to 'version' text //UINT uVersionLen; DWORD dwVerHnd=0; // An 'ignored' parameter, always '0' //VS_FIXEDFILEINFO vsFileInfo; FixFilePath (szFileName, FileLoc); // Add necessary path prefix to file name DWORD dwVerInfoSize = GetFileVersionInfoSize (szFileName, &dwVerHnd); if (!dwVerInfoSize) // Cannot reach the DLL file return FALSE; LPSTR lpstrVffInfo = (LPSTR) malloc (dwVerInfoSize); // Alloc memory for file info if (lpstrVffInfo == NULL) return FALSE; // Allocation failed // Try to get the info if (!GetFileVersionInfo(szFileName, dwVerHnd, dwVerInfoSize, lpstrVffInfo)) { free (lpstrVffInfo); return FALSE; // Cannot read the file information - // wierd, since we could read the information size } /* The below 'hex' value looks a little confusing, but essentially what it is, is the hexidecimal representation of a couple different values that represent the language and character set that we are wanting string values for. 040904E4 is a very common one, because it means: US English, Windows MultiLingual characterset Or to pull it all apart: 04------ = SUBLANG_ENGLISH_USA --09---- = LANG_ENGLISH ----04E4 = 1252 = Codepage for Windows:Multilingual */ /*static char fileVersion[256]; LPVOID version=NULL; DWORD vLen,langD; BOOL retVal; sprintf(fileVersion,"\\VarFileInfo\\Translation"); retVal = VerQueryValue ( lpstrVffInfo, fileVersion, &version, (UINT *)&uVersionLen); if (retVal && vLen==4) { memcpy(&langD,version,4); sprintf(fileVersion, "\\StringFileInfo\\%02X%02X%02X%02X\\FileVersion", (langD & 0xff00)>>8,langD & 0xff,(langD & 0xff000000)>>24, (langD & 0xff0000)>>16); } else sprintf(fileVersion,"\\StringFileInfo\\%04X04B0\\FileVersion",GetUserDefaultLangID()); if (!VerQueryValue ( lpstrVffInfo, fileVersion, (LPVOID *)&lpVersion, (UINT *)&uVersionLen)) { free (lpstrVffInfo); return FALSE; // Query was unsuccessful } */ // Now we have a string that looks like this : // "MajorVersion.MinorVersion.BuildNumber", so let's parse it lpVersion = getVersion(szFileName); m_stFullVersion = getVersion(szFileName); BOOL bRes = ParseVersionString (lpVersion, dwMajor, dwMinor, dwBuildNumber); if(!bRes) // Lets try for commas bRes = ParseVersionString1 (lpVersion, dwMajor, dwMinor, dwBuildNumber); free (lpstrVffInfo); return bRes; }