Changeset 93391 in vbox for trunk/src/VBox/Installer/win/Stub
- Timestamp:
- Jan 21, 2022 10:06:36 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/win/Stub/VBoxStub.cpp
r93390 r93391 20 20 * Header Files * 21 21 *********************************************************************************************************************************/ 22 #if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x050123 # undef _WIN32_WINNT24 # define _WIN32_WINNT 0x0501 /* AttachConsole() / FreeConsole(). */25 #endif26 27 22 #include <iprt/win/windows.h> 28 23 #include <iprt/win/commctrl.h> … … 66 61 #endif 67 62 68 #ifndef TARGET_NT469 /* Use an own console window if run in verbose mode. */70 # define VBOX_STUB_WITH_OWN_CONSOLE71 #endif72 73 63 74 64 /********************************************************************************************************************************* … … 77 67 #define MY_UNICODE_SUB(str) L ##str 78 68 #define MY_UNICODE(str) MY_UNICODE_SUB(str) 69 70 /* Use an own console window if run in verbose mode. */ 71 #define VBOX_STUB_WITH_OWN_CONSOLE 79 72 80 73 … … 866 859 if (RT_FAILURE(vrc)) 867 860 return RTMsgInitFailure(vrc); 868 869 /*870 * Check if we're already running and jump out if so.871 *872 * Note! Do not use a global namespace ("Global\\") for mutex name here,873 * will blow up NT4 compatibility!874 */875 HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, "VBoxStubInstaller");876 if ( hMutexAppRunning != NULL877 && GetLastError() == ERROR_ALREADY_EXISTS)878 {879 /* Close the mutex for this application instance. */880 CloseHandle(hMutexAppRunning);881 hMutexAppRunning = NULL;882 return RTEXITCODE_FAILURE;883 }884 861 885 862 /* … … 938 915 }; 939 916 940 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 941 942 /* Parse the parameters. */ 917 RTGETOPTSTATE GetState; 918 vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0); 919 AssertRCReturn(vrc, ShowError("RTGetOptInit failed: %Rrc", vrc)); 920 921 /* Loop over the arguments. */ 943 922 int ch; 944 bool fExitEarly = false;945 923 RTGETOPTUNION ValueUnion; 946 RTGETOPTSTATE GetState; 947 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0); 948 while ( (ch = RTGetOpt(&GetState, &ValueUnion)) 949 && rcExit == RTEXITCODE_SUCCESS 950 && !fExitEarly) 924 while ((ch = RTGetOpt(&GetState, &ValueUnion)) != 0) 951 925 { 952 926 switch (ch) … … 956 930 vrc = RTStrCat(szMSIArgs, sizeof(szMSIArgs), " "); 957 931 if (RT_SUCCESS(vrc)) 958 vrc = RTStrCat(szMSIArgs, sizeof(szMSIArgs), 959 "REINSTALLMODE=vomus REINSTALL=ALL"); 932 vrc = RTStrCat(szMSIArgs, sizeof(szMSIArgs), "REINSTALLMODE=vomus REINSTALL=ALL"); 960 933 if (RT_FAILURE(vrc)) 961 r cExit =ShowSyntaxError("Out of space for MSI parameters and properties");934 return ShowSyntaxError("Out of space for MSI parameters and properties"); 962 935 break; 963 936 … … 982 955 vrc = RTStrCopy(szExtractPath, sizeof(szExtractPath), ValueUnion.psz); 983 956 if (RT_FAILURE(vrc)) 984 r cExit =ShowSyntaxError("Extraction path is too long.");957 return ShowSyntaxError("Extraction path is too long."); 985 958 break; 986 959 … … 991 964 vrc = RTStrCat(szMSIArgs, sizeof(szMSIArgs), ValueUnion.psz); 992 965 if (RT_FAILURE(vrc)) 993 r cExit =ShowSyntaxError("Out of space for MSI parameters and properties");966 return ShowSyntaxError("Out of space for MSI parameters and properties"); 994 967 break; 995 968 … … 1006 979 strpbrk(ValueUnion.psz, " \t\n\r") == NULL ? "%s%s=%s" : "%s%s=\"%s\"", 1007 980 cchMsiArgs ? " " : "", pszProp, ValueUnion.psz) <= 1) 1008 r cExit =ShowSyntaxError("Out of space for MSI parameters and properties");981 return ShowSyntaxError("Out of space for MSI parameters and properties"); 1009 982 } 1010 983 else if (vrc == VERR_GETOPT_REQUIRED_ARGUMENT_MISSING) 1011 r cExit =ShowSyntaxError("--msi-prop takes two arguments, the 2nd is missing");984 return ShowSyntaxError("--msi-prop takes two arguments, the 2nd is missing"); 1012 985 else 1013 r cExit =ShowSyntaxError("Failed to get 2nd --msi-prop argument: %Rrc", vrc);986 return ShowSyntaxError("Failed to get 2nd --msi-prop argument: %Rrc", vrc); 1014 987 } 1015 988 else 1016 r cExit =ShowSyntaxError("The first argument to --msi-prop must not contain spaces: %s", pszProp);989 return ShowSyntaxError("The first argument to --msi-prop must not contain spaces: %s", pszProp); 1017 990 break; 1018 991 } … … 1024 997 case 'V': 1025 998 ShowInfo("Version: %u.%u.%ur%u", VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV); 1026 fExitEarly = true; 1027 break; 999 return RTEXITCODE_SUCCESS; 1028 1000 1029 1001 case 'v': … … 1067 1039 VBOX_STUB_TITLE, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV, 1068 1040 argv[0], argv[0]); 1069 fExitEarly = true; 1070 break; 1041 return RTEXITCODE_SUCCESS; 1071 1042 1072 1043 case VINF_GETOPT_NOT_OPTION: … … 1080 1051 vrc = RTStrCat(szMSIArgs, sizeof(szMSIArgs), ValueUnion.psz); 1081 1052 if (RT_FAILURE(vrc)) 1082 r cExit =ShowSyntaxError("Out of space for MSI parameters and properties");1053 return ShowSyntaxError("Out of space for MSI parameters and properties"); 1083 1054 continue; 1084 1055 } … … 1087 1058 default: 1088 1059 if (g_fSilent) 1089 r cExit =RTGetOptPrintError(ch, &ValueUnion);1060 return RTGetOptPrintError(ch, &ValueUnion); 1090 1061 if (ch == VERR_GETOPT_UNKNOWN_OPTION) 1091 rcExit = ShowSyntaxError("Unknown option \"%s\"\n" 1092 "Please refer to the command line help by specifying \"-?\"\n" 1093 "to get more information.", ValueUnion.psz); 1094 else 1095 rcExit = ShowSyntaxError("Parameter parsing error: %Rrc\n" 1096 "Please refer to the command line help by specifying \"-?\"\n" 1097 "to get more information.", ch); 1098 break; 1062 return ShowSyntaxError("Unknown option \"%s\"\n" 1063 "Please refer to the command line help by specifying \"-?\"\n" 1064 "to get more information.", ValueUnion.psz); 1065 return ShowSyntaxError("Parameter parsing error: %Rrc\n" 1066 "Please refer to the command line help by specifying \"-?\"\n" 1067 "to get more information.", ch); 1099 1068 } 1100 1069 } 1101 1070 1102 /* Check if we can bail out early. */ 1103 if (fExitEarly) 1104 return rcExit; 1105 1106 if (rcExit != RTEXITCODE_SUCCESS) 1107 vrc = VERR_PARSE_ERROR; 1071 /* Set the default extraction path if not given the the user. */ 1072 if (szExtractPath[0] == '\0') 1073 { 1074 vrc = RTPathTemp(szExtractPath, sizeof(szExtractPath)); 1075 if (RT_SUCCESS(vrc)) 1076 vrc = RTPathAppend(szExtractPath, sizeof(szExtractPath), "VirtualBox"); 1077 if (RT_FAILURE(vrc)) 1078 return ShowError("Failed to construct extraction path: %Rrc", vrc); 1079 } 1080 RTPathChangeToDosSlashes(szExtractPath, true /* Force conversion. */); /* MSI requirement. */ 1081 1082 /* 1083 * Check if we're already running and jump out if so (this is mainly to 1084 * protect the TEMP directory usage, right?). 1085 */ 1086 SetLastError(0); 1087 HANDLE hMutexAppRunning = CreateMutex(NULL, FALSE, "VBoxStubInstaller"); 1088 if ( hMutexAppRunning != NULL 1089 && GetLastError() == ERROR_ALREADY_EXISTS) 1090 { 1091 CloseHandle(hMutexAppRunning); /* close it so we don't keep it open while showing the error message. */ 1092 return ShowError("Another installer is already running"); 1093 } 1108 1094 1109 1095 /** @todo … … 1112 1098 * 1113 1099 * */ 1114 1115 #if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0501 1116 # ifdef VBOX_STUB_WITH_OWN_CONSOLE /* Use an own console window if run in debug mode. */ 1117 if ( RT_SUCCESS(vrc) 1118 && g_iVerbosity) 1100 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 1101 1102 /* 1103 * Create a console for output if we're in verbose mode. 1104 */ 1105 #ifdef VBOX_STUB_WITH_OWN_CONSOLE 1106 if (g_iVerbosity) 1119 1107 { 1120 1108 if (!AllocConsole()) 1121 { 1122 DWORD dwErr = GetLastError(); 1123 ShowError("Unable to allocate console, error = %ld\n", 1124 dwErr); 1125 1126 /* Close the mutex for this application instance. */ 1127 CloseHandle(hMutexAppRunning); 1128 hMutexAppRunning = NULL; 1129 return RTEXITCODE_FAILURE; 1130 } 1109 return ShowError("Unable to allocate console: LastError=%u\n", GetLastError()); 1131 1110 1132 1111 freopen("CONOUT$", "w", stdout); … … 1135 1114 freopen("CONOUT$", "w", stderr); 1136 1115 } 1137 # endif /* VBOX_STUB_WITH_OWN_CONSOLE */ 1138 #endif 1139 1140 if ( RT_SUCCESS(vrc) 1141 && g_iVerbosity) 1116 #endif /* VBOX_STUB_WITH_OWN_CONSOLE */ 1117 1118 if (g_iVerbosity) 1142 1119 { 1143 1120 RTPrintf("Silent installation : %RTbool\n", g_fSilent); … … 1146 1123 RTPrintf("Certificate installation : %RTbool\n", fEnableSilentCert); 1147 1124 #endif 1148 RTPrintf("Additional MSI parameters: %s\n", 1149 szMSIArgs[0] ? szMSIArgs : "<None>"); 1125 RTPrintf("Additional MSI parameters: %s\n", szMSIArgs[0] ? szMSIArgs : "<None>"); 1150 1126 } 1151 1127 … … 1156 1132 && !g_fSilent 1157 1133 && !IsWow64()) 1158 {1159 1134 rcExit = ShowError("32-bit Windows hosts are not supported by this VirtualBox release."); 1160 vrc = VERR_NOT_SUPPORTED; 1161 } 1162 1163 if (RT_SUCCESS(vrc)) 1135 else 1164 1136 { 1165 1137 /* 1166 * Determine the extration path if not given by the user, and gather some 1167 * other bits we'll be needing later. 1138 * Read our manifest. 1168 1139 */ 1169 if (szExtractPath[0] == '\0') 1170 { 1171 vrc = RTPathTemp(szExtractPath, sizeof(szExtractPath)); 1172 if (RT_SUCCESS(vrc)) 1173 vrc = RTPathAppend(szExtractPath, sizeof(szExtractPath), "VirtualBox"); 1174 if (RT_FAILURE(vrc)) 1175 ShowError("Failed to determine extraction path (%Rrc)", vrc); 1176 1177 } 1178 else 1179 { 1180 /** @todo should check if there is a .custom subdirectory there or not. */ 1181 } 1182 RTPathChangeToDosSlashes(szExtractPath, 1183 true /* Force conversion. */); /* MSI requirement. */ 1184 } 1185 1186 /* Read our manifest. */ 1187 if (RT_SUCCESS(vrc)) 1188 { 1189 PVBOXSTUBPKGHEADER pHeader; 1140 PVBOXSTUBPKGHEADER pHeader = NULL; 1190 1141 vrc = FindData("MANIFEST", (PVOID *)&pHeader, NULL); 1191 1142 if (RT_SUCCESS(vrc)) … … 1198 1149 /* 1199 1150 * Up to this point, we haven't done anything that requires any cleanup. 1200 * From here on, we do everything in function so we can counter clean up.1151 * From here on, we do everything in functions so we can counter clean up. 1201 1152 */ 1202 bool fCreatedExtractDir; 1203 rcExit = ExtractFiles(pHeader->byCntPkgs, szExtractPath, 1204 fExtractOnly, &fCreatedExtractDir); 1153 bool fCreatedExtractDir = false; 1154 rcExit = ExtractFiles(pHeader->byCntPkgs, szExtractPath, fExtractOnly, &fCreatedExtractDir); 1205 1155 if (rcExit == RTEXITCODE_SUCCESS) 1206 1156 { … … 1223 1173 iPackage++; 1224 1174 } 1225 1226 /* Don't fail if cleanup fail. At least for now. */1227 CleanUp( !fEnableLogging1228 && fCreatedExtractDir ? szExtractPath : NULL);1229 1175 } 1230 1176 } 1177 1178 /* 1179 * Do cleanups unless we're only extracting (ignoring failures for now). 1180 */ 1181 if (!fExtractOnly) 1182 CleanUp(!fEnableLogging && fCreatedExtractDir ? szExtractPath : NULL); 1231 1183 1232 1184 /* Free any left behind cleanup records (not strictly needed). */ … … 1250 1202 1251 1203 /* 1252 * Release instance mutex .1204 * Release instance mutex just to be on the safe side. 1253 1205 */ 1254 1206 if (hMutexAppRunning != NULL) 1255 {1256 1207 CloseHandle(hMutexAppRunning); 1257 hMutexAppRunning = NULL;1258 }1259 1208 1260 1209 return rcExit != (RTEXITCODE)ERROR_SUCCESS_REBOOT_REQUIRED || !fIgnoreReboot ? rcExit : RTEXITCODE_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.