winsdk: Clean up confiure_runtime.c and docs
authorLenny Komow <lenny@lunarg.com>
Fri, 12 Aug 2016 19:26:20 +0000 (13:26 -0600)
committerLenny Komow <lenny@lunarg.com>
Fri, 12 Aug 2016 20:35:24 +0000 (14:35 -0600)
windowsRuntimeInstaller/InstallerRT.nsi
windowsRuntimeInstaller/README.txt
windowsRuntimeInstaller/configure_runtime.c

index da19393..79c7a5f 100644 (file)
@@ -233,17 +233,17 @@ VIAddVersionKey  "LegalCopyright" ""
 !endif
 
 
-# Function to run ConfigLayersAndVulkanDll ps script.
+# Function to run ConfigureRT program.
 # Return value is in $0 - 0 is success, all else is failure.
 !macro ConfigLayersAndVulkanDLL un
 Function ${un}ConfigLayersAndVulkanDLL
-\r
-    # Execute the configuration program\r
-    nsExec::ExecToStack 'ConfigureRT.exe --abi-major ${VERSION_ABI_MAJOR}'\r
-    Rename "configure_rt.log" "$TEMP\VulkanRT\configure_rt.log"\r
-    pop $0\r
-\r
-    # Ignore errors. If something went wrong, the return value will indicate it.\r
+
+    # Execute the configuration program
+    nsExec::ExecToStack 'ConfigureRT.exe --abi-major ${VERSION_ABI_MAJOR}'
+    Rename "configure_rt.log" "$TEMP\VulkanRT\configure_rt.log"
+    pop $0
+
+    # Ignore errors. If something went wrong, the return value will indicate it.
     ClearErrors
 
 FunctionEnd
@@ -252,13 +252,13 @@ FunctionEnd
 !insertmacro ConfigLayersAndVulkanDLL "un."
 
 
-# Function to run diagnostics if ConfigLayersAndVulkanDll ps script failed.
-# On entry $0, contains the return value from ConfigLayersAndVulkanDll.ps1. It shouldn't be changed.
+# Function to run diagnostics if ConfigureRT program failed.
+# On entry $0, contains the return value from ConfigureRT.exe. It shouldn't be changed.
 !macro DiagConfigLayersAndVulkanDLL un
-Function ${un}DiagConfigLayersAndVulkanDLL\r
-    # Report the failure\r
-    LogText "ConfigureRT.exe failed with return code $0"\r
-\r
+Function ${un}DiagConfigLayersAndVulkanDLL
+    # Report the failure
+    LogText "ConfigureRT.exe failed with return code $0"
+
     # Ignore errors
     ClearErrors
 
@@ -330,7 +330,7 @@ Section
     File ${ICOFILE}
     File VULKANRT_LICENSE.RTF
     File /oname=LICENSE.txt ..\COPYRIGHT.txt
-    File Release\ConfigureRT.exe\r
+    File Release\ConfigureRT.exe
     StrCpy $1 15
     Call CheckForError
 
@@ -466,7 +466,7 @@ Section
 
     ${Endif}
 
-    # Run the ConfigLayersAndVulkanDLL.ps1 script to copy the most recent version of
+    # Run the ConfigureRT program to copy the most recent version of
     # vulkan-<abimajor>-*.dll to vulkan-<abimajor>.dll, and to set up layer registry
     # entries to use layers from the corresponding SDK
     SetOutPath "$INSTDIR"
@@ -475,7 +475,7 @@ Section
         SetOutPath "$INSTDIR"
         Call DiagConfigLayersAndVulkanDLL
 
-        # The Powershell script failed, and we don't know why.
+        # The program failed, and we don't know why.
         # Simply configure system to use our loader and vulkaninfo.
         MessageBox MB_OK "Warning!$\n$\nPowershell script called by VulkanRT Installer failed with error $0. Is Powershell installed on your system?$\n$\nWill configure system with Vulkan $FileVersion." /SD IDOK
         ${If} ${RunningX64}
@@ -493,9 +493,9 @@ Section
     StrCpy $1 60
     Call CheckForError
 
-    # We are done using ConfigLayersAndVulkanDLL.ps1, delete it. It will be re-installed
+    # We are done using ConfigureRT.exe, delete it. It will be re-installed
     # by the uninstaller when it needs to be run again during uninstall.
-    Delete ConfigureRT.exe\r
+    Delete ConfigureRT.exe
 
     # Finish logging and move log file to TEMP dir
     LogSet off
@@ -568,9 +568,9 @@ Section "uninstall"
     Call un.CheckForError
 
 
-    # Install the ConfigLayersAndVulkanDLL.ps1 so we can run it.
+    # Install ConfigureRT.exe so we can run it.
     # It will be deleted later when we remove the install directory.
-    File Release\ConfigureRT.exe\r
+    File Release\ConfigureRT.exe
 
     # If running on a 64-bit OS machine
     ${If} ${RunningX64}
@@ -615,7 +615,7 @@ Section "uninstall"
 
     ${Endif}
 
-    # Run the ConfigLayersAndVulkanDLL.ps1 script to copy the most recent version of
+    # Run the ConfigureRT.exe program to copy the most recent version of
     # vulkan-<abimajor>-*.dll to vulkan-<abimajor>.dll, and to set up layer registry
     # entries to use layers from the corresponding SDK
     SetOutPath "$IDir"
@@ -644,7 +644,7 @@ Section "uninstall"
         Delete /REBOOTOK "$IDir\LICENSE.txt"
         Delete /REBOOTOK "$IDir\Uninstall${PRODUCTNAME}.exe"
         Delete /REBOOTOK "$IDir\V.ico"
-        Delete /REBOOTOK "$IDir\ConfigureRT.exe"\r
+        Delete /REBOOTOK "$IDir\ConfigureRT.exe"
         Delete /REBOOTOK "$IDir\vulkaninfo.exe"
 
         # If running on a 64-bit OS machine
index 02dce10..a8f7df5 100644 (file)
@@ -78,7 +78,7 @@ Some notes on the behavior of the Windows Vulkan Runtime Installer:
       the Vulkan runtime.  When it is run on a 32-bit version of\r
       Windows, it will install the 32 bit version of the Vulkan runtime.\r
 \r
-   o  The VulkanRT-<version>-Installer.exe created with the above steps\r
+   o  The VulkanRT-<version>-Installer.exe created with the above ste`\r
       can be run in silent mode by using the /S command line option when\r
       invoking the installer.\r
 \r
@@ -109,9 +109,9 @@ Some notes on the behavior of the Windows Vulkan Runtime Installer:
 \r
    o  The Vulkan Runtime Installer installs the Vulkan loader as\r
       C:\Windows\System32\vulkan-<version>.dll. It then runs the\r
-      Powershell script ConfigLayersAndVulkanDLL.ps1, that compares\r
-      versions of the loader in C:\Windows\System32 that have the\r
-      same VERSION_ABI_MAJOR as the version being installed. The\r
+      program ConfigureRT.exe (the source for which is included), that\r
+      compares versions of the loader in C:\Windows\System32 that have\r
+      the same VERSION_ABI_MAJOR as the version being installed. The\r
       script selects the most recent one of these loader files and\r
       copies it to C:\Windows\System32\vulkan-<VERSION_ABI_MAJOR>.dll.\r
       For example, during the install of Vulkan Runtime version 2.0.1.1,\r
@@ -145,8 +145,8 @@ Some notes on the behavior of the Windows Vulkan Runtime Installer:
        HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\VulkanRT<version>\UninstallString\r
 \r
    o The Installer and Uninstaller create log files, which can be\r
-     found in the VulkanrRT folder in the current TEMP folder.\r
+     found in the VulkanRT folder in the current TEMP folder.\r
      (The TEMP folder is generally identified by the TEMP environment\r
      variable). In addition to installer/uninstaller logs files,\r
      the folder also contains a log from the last run of the\r
-     ConfigLayersAndVulkanDLL.ps1 script.\r
+     ConfigureRT.exe program.\r
index 5f80663..10cf571 100644 (file)
@@ -30,9 +30,8 @@
  * - Set the layer registry entried to point to the layer json files in\r
  *   the Vulkan SDK associated with the most recent vulkan*.dll\r
  *\r
- * The program must be called with the following two parameters:\r
+ * The program must be called with the following parameters:\r
  *     --major-abi: A single number specifying the major abi version\r
- *     --ossize: A single integer indicating a 32 or 64 bit OS\r
  */\r
 \r
 // Compile with: `cl.exe configure_runtime.c /link advapi32.lib`\r
 #define snprintf _snprintf\r
 #endif\r
 \r
+#if defined(_WIN64)\r
+#error "This program is designed only as a 32-bit program. It should not be built as 64-bit."\r
+#endif\r
+\r
 #define COPY_BUFFER_SIZE (1024)\r
 #define CHECK_ERROR(statement) { int error = (statement); if(error) return error; }\r
 #define CHECK_ERROR_HANDLED(statement, handler) { int error = (statement); if(error) { { handler } return error; } }\r
@@ -74,7 +77,6 @@ struct SDKVersion
 };\r
 \r
 const char* FLAG_ABI_MAJOR = "--abi-major";\r
-const char* FLAG_OS_SIZE = "--ossize";\r
 const char* PATH_SYSTEM32 = "\\SYSTEM32\\";\r
 const char* PATH_SYSWOW64 = "\\SysWOW64\\";\r
 \r
@@ -94,11 +96,6 @@ int add_explicit_layers(FILE* log, const char* install_path, enum Platform platf
 // Returns: Zero if they are equal, below zero if a predates b, greater than zero if b predates a\r
 int compare_versions(const struct SDKVersion* a, const struct SDKVersion* b);\r
 \r
-// Copy a binary file\r
-//\r
-// Returns: Zero on success, an error code on failure\r
-int copy_file(const char* destination, const char* source);\r
-\r
 // Locate all of the SDK installations\r
 //\r
 // install_paths (output) - A poiner to an array of the installations paths\r
@@ -163,11 +160,11 @@ int update_registry_layers(FILE* log, enum Platform platform, const struct SDKVe
 // extension (input) - The file extensions of the file to be updated\r
 // path (input) - The directory of the file (usually System32 or SysWOW64)\r
 // abi_major (input) - The ABI major version to be updated\r
-// append_abi_major (input) - Whether or not the ABI number should be appended to the filename\r
+// leave_abi_major (input) - Whether or not the ABI number be left on the output filename\r
 // latest_version (output) - The version of the runtime which the file was updated to\r
 // Returns: Zero on success, an error code on failure\r
 int update_system_file(FILE* log, const char* name, const char* extension, const char* path,\r
-    long abi_major, bool append_abi_major, struct SDKVersion* latest_version);\r
+    long abi_major, bool leave_abi_major, struct SDKVersion* latest_version);\r
 \r
 // Update vulkan.dll and vulkaninfo.exe in all of the windows directories (System32 and SysWOW64)\r
 //\r
@@ -221,6 +218,8 @@ int add_explicit_layers(FILE* log, const char* install_path, enum Platform platf
         break;\r
     }\r
 \r
+    // If this is a 32 bit system, we allow redirection to point this at the 32-bit registries.\r
+    // If not, we add the flag KEY_WOW64_64KEY, to disable redirection for this node.\r
     HKEY hKey;\r
     REGSAM flags = KEY_ALL_ACCESS;\r
     if(platform == PLATFORM_X64) {\r
@@ -283,46 +282,14 @@ int compare_versions(const struct SDKVersion* a, const struct SDKVersion* b)
     return strncmp(a->extended, b->extended, SDK_VERSION_BUFFER_SIZE);\r
 }\r
 \r
-int copy_file(const char* destination, const char* source)\r
-{\r
-    // Open files for reading and writing\r
-    FILE* src = fopen(source, "rb");\r
-    FILE* dest = fopen(destination, "wb");\r
-    if(src == NULL || dest == NULL) {\r
-        return 60;\r
-    }\r
-    \r
-    // Stream the data between the two files\r
-    uint8_t buffer[COPY_BUFFER_SIZE];\r
-    size_t read_size;\r
-    do {\r
-        read_size = fread(buffer, sizeof(uint8_t), COPY_BUFFER_SIZE, src);\r
-        if(ferror(src)) {\r
-            fclose(src);\r
-            fclose(dest);\r
-            return 70;\r
-        }\r
-        size_t write_size = fwrite(buffer, sizeof(uint8_t), read_size, dest);\r
-        if(ferror(dest)) {\r
-            fclose(src);\r
-            fclose(dest);\r
-            return 80;\r
-        }\r
-    } while(read_size == COPY_BUFFER_SIZE);\r
-    \r
-    // Clean up\r
-    fclose(src);\r
-    fclose(dest);\r
-    \r
-    return 0;\r
-}\r
-\r
 int find_installations(char*** install_paths, struct SDKVersion** install_versions, size_t* count)\r
 {\r
     *install_paths = malloc(sizeof(char*) * 64);\r
     *install_versions = malloc(sizeof(struct SDKVersion) * 64);\r
     *count = 0;\r
 \r
+    // We want the 64-bit registries on 64-bit windows, and the 32-bit registries on 32-bit Windows.\r
+    // KEY_WOW64_64KEY accomplishes this because it gets ignored on 32-bit Windows.\r
     HKEY hKey;\r
     if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",\r
         0, KEY_READ | KEY_WOW64_64KEY, &hKey) != ERROR_SUCCESS) {\r
@@ -502,6 +469,8 @@ int remove_explicit_layers(FILE* log, const char** install_paths, size_t count,
 \r
     bool removed_one;\r
     do {\r
+        // If this is a 32 bit system, we allow redirection to point this at the 32-bit registries.\r
+        // If not, we add the flag KEY_WOW64_64KEY, to disable redirection for this node.\r
         HKEY hKey;\r
         REGSAM flags = KEY_ALL_ACCESS;\r
         if(platform == PLATFORM_X64) {\r
@@ -585,27 +554,16 @@ int update_registry_layers(FILE* log, enum Platform platform, const struct SDKVe
 }\r
 \r
 int update_system_file(FILE* log, const char* name, const char* extension, const char* path,\r
-    long abi_major, bool append_abi_major, struct SDKVersion* latest_version)\r
+    long abi_major, bool leave_abi_major, struct SDKVersion* latest_version)\r
 {\r
     // Generate the filter string\r
-    char* filter;\r
-    if(append_abi_major) {\r
-        const char* pattern = "%s%s-%ld-*-*-*-*%s";\r
-        int filter_size = snprintf(NULL, 0, pattern, path, name, abi_major, extension) + 1;\r
-        if(filter_size < 0) {\r
-            return 180;\r
-        }\r
-        filter = malloc(filter_size);\r
-        snprintf(filter, filter_size, pattern, path, name, abi_major, extension);\r
-    } else {\r
-        const char* pattern = "%s%s-*-*-*-*%s";\r
-        int filter_size = snprintf(NULL, 0, pattern, path, name, extension) + 1;\r
-        if(filter_size < 0) {\r
-            return 190;\r
-        }\r
-        filter = malloc(filter_size);\r
-        snprintf(filter, filter_size, pattern, path, name, extension);\r
+    const char* pattern = "%s%s-%ld-*-*-*-*%s";\r
+    int filter_size = snprintf(NULL, 0, pattern, path, name, abi_major, extension) + 1;\r
+    if(filter_size < 0) {\r
+        return 180;\r
     }\r
+    char* filter = malloc(filter_size);\r
+    snprintf(filter, filter_size, pattern, path, name, abi_major, extension);\r
     \r
     // Find all of the files that match the pattern\r
     char* latest_filename = malloc(64);\r
@@ -622,14 +580,14 @@ int update_system_file(FILE* log, const char* name, const char* extension, const
         // Decide if this is the latest file\r
         if(compare_versions(latest_version, &version) < 0) {\r
             *latest_version = version;\r
-            const char* pattern = "%s%s";\r
-            int size = snprintf(NULL, 0, pattern, path, find_data.cFileName) + 1;\r
+            const char* latestPattern = "%s%s";\r
+            int size = snprintf(NULL, 0, latestPattern, path, find_data.cFileName) + 1;\r
             if(size < 0) {\r
                 free(latest_filename);\r
                 return 200;\r
             }\r
             latest_filename = realloc(latest_filename, size);\r
-            snprintf(latest_filename, size, pattern, path, find_data.cFileName);\r
+            snprintf(latest_filename, size, latestPattern, path, find_data.cFileName);\r
         }\r
     }\r
     FindClose(find);\r
@@ -645,13 +603,26 @@ int update_system_file(FILE* log, const char* name, const char* extension, const
         latest_version->minor, latest_version->patch, latest_version->build);\r
         \r
     // Generate output filename\r
-    const char* pattern = "%s%s%s";\r
-    int out_size = snprintf(NULL, 0, pattern, path, name, extension) + 1;\r
-    if(out_size < 0) {\r
-        return 210;\r
+    char* output_filename;\r
+    if(leave_abi_major) {\r
+        const char* outPattern = "%s%s-%ld%s";\r
+        int out_size = snprintf(NULL, 0, outPattern, path, name, abi_major, extension) + 1;\r
+        if(out_size < 0) {\r
+            free(latest_filename);\r
+            return 205;\r
+        }\r
+        output_filename = malloc(out_size);\r
+        snprintf(output_filename, out_size, outPattern, path, name, abi_major, extension);\r
+    } else {\r
+        const char* outPattern = "%s%s%s";\r
+        int out_size = snprintf(NULL, 0, outPattern, path, name, extension) + 1;\r
+        if(out_size < 0) {\r
+            free(latest_filename);\r
+            return 210;\r
+        }\r
+        output_filename = malloc(out_size);\r
+        snprintf(output_filename, out_size, outPattern, path, name, extension);\r
     }\r
-    char* output_filename = malloc(out_size);\r
-    snprintf(output_filename, out_size, pattern, path, name, extension);\r
     \r
     // Remove any older version of the output file\r
     if(remove(output_filename) == 0) {\r
@@ -661,9 +632,14 @@ int update_system_file(FILE* log, const char* name, const char* extension, const
     }\r
     \r
     fprintf(log, "Attempting to copy file %s to %s\n", latest_filename, output_filename);\r
-    CHECK_ERROR_HANDLED(copy_file(output_filename, latest_filename), { free(latest_filename); });\r
+    if(CopyFile(latest_filename, output_filename, false) == 0) {\r
+        free(latest_filename);\r
+        free(output_filename);\r
+        return 215;\r
+    }\r
     \r
     free(latest_filename);\r
+    free(output_filename);\r
     return 0;\r
 }\r
 \r
@@ -677,25 +653,28 @@ int update_windows_directories(FILE* log, long abi_major, enum Platform platform
 \r
     strcpy(system_path + windows_path_size - 1, PATH_SYSTEM32);\r
     fprintf(log, "Updating system directory: %s\n", system_path);\r
-    CHECK_ERROR_HANDLED(update_system_file(log, "vulkan-1", ".dll", system_path, abi_major, false,\r
+    CHECK_ERROR_HANDLED(update_system_file(log, "vulkan", ".dll", system_path, abi_major, true,\r
         latest_runtime_version), { free(system_path); });\r
-    CHECK_ERROR_HANDLED(update_system_file(log, "vulkaninfo", ".exe", system_path, abi_major, true,\r
+    CHECK_ERROR_HANDLED(update_system_file(log, "vulkaninfo", ".exe", system_path, abi_major, false,\r
         &version), { free(system_path); });\r
     if(compare_versions(latest_runtime_version, &version) != 0) {\r
+        free(system_path);\r
         return 220;\r
     }\r
 \r
     if(platform == PLATFORM_X64) {\r
         strcpy(system_path + windows_path_size - 1, PATH_SYSWOW64);\r
         fprintf(log, "\nUpdating system directory: %s\n", system_path);\r
-        CHECK_ERROR_HANDLED(update_system_file(log, "vulkan-1", ".dll", system_path, abi_major,\r
-            false, &version), { free(system_path); });\r
+        CHECK_ERROR_HANDLED(update_system_file(log, "vulkan", ".dll", system_path, abi_major,\r
+            true, &version), { free(system_path); });\r
         if(compare_versions(latest_runtime_version, &version) != 0) {\r
+            free(system_path);\r
             return 230;\r
         }\r
         CHECK_ERROR_HANDLED(update_system_file(log, "vulkaninfo", ".exe", system_path, abi_major,\r
-            true, &version), { free(system_path); });\r
+            false, &version), { free(system_path); });\r
         if(compare_versions(latest_runtime_version, &version) != 0) {\r
+            free(system_path);\r
             return 240;\r
         }\r
     }\r