verchk.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "verchk.h"
  19. #include "wolsetup.h"
  20. #include <windows.h>
  21. #include <winnt.h>
  22. #include <stdlib.h>
  23. /**
  24. * Retrieve version information from files version resource.
  25. *
  26. * INPUTS
  27. * Filename - Name of file to retrieve version information for.
  28. * FileInfo - Pointer to VS_FIXEDFILEINFO structure to be filled in.
  29. *
  30. * RESULT
  31. * Success - True if successful in obtaining version information.
  32. */
  33. bool GetVersionInfo(char* filename, VS_FIXEDFILEINFO* fileInfo)
  34. {
  35. if (filename == NULL || fileInfo == NULL)
  36. {
  37. return false;
  38. }
  39. // Get version information from the application
  40. DWORD verHandle;
  41. DWORD verInfoSize = GetFileVersionInfoSize(filename, &verHandle);
  42. if (verInfoSize)
  43. {
  44. // If we were able to get the information, process it:
  45. HANDLE memHandle = GlobalAlloc(GMEM_MOVEABLE, verInfoSize);
  46. if (memHandle)
  47. {
  48. LPVOID buffer = GlobalLock(memHandle);
  49. if (buffer)
  50. {
  51. BOOL success = GetFileVersionInfo(filename, verHandle, verInfoSize, buffer);
  52. if (success)
  53. {
  54. VS_FIXEDFILEINFO* data;
  55. UINT dataSize = 0;
  56. success = VerQueryValue(buffer, "\\", (LPVOID*) & data, &dataSize);
  57. if (success && (dataSize == sizeof(VS_FIXEDFILEINFO)))
  58. {
  59. memcpy(fileInfo, data, sizeof(VS_FIXEDFILEINFO));
  60. return true;
  61. }
  62. }
  63. GlobalUnlock(memHandle);
  64. }
  65. GlobalFree(memHandle);
  66. }
  67. }
  68. return false;
  69. }
  70. bool loadWolapi( char *filename )
  71. {
  72. VS_FIXEDFILEINFO fileInfo;
  73. if (GetVersionInfo(filename, &fileInfo))
  74. g_wolapiInstalled = false;
  75. return g_wolapiInstalled;
  76. }