Changeset 85778 in vbox
- Timestamp:
- Aug 14, 2020 8:54:43 PM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r85683 r85778 163 163 { "cloudprofile", USAGE_S_NEWCMD, HELP_CMD_CLOUDPROFILE, handleCloudProfile, 0 }, 164 164 { "cloud", USAGE_S_NEWCMD, HELP_CMD_CLOUD, handleCloud, 0 }, 165 { "updatecheck", USAGE_ UPDATECHECK, HELP_CMD_UPDATECHECK, handleUpdateCheck,0 }165 { "updatecheck", USAGE_S_NEWCMD, HELP_CMD_UPDATECHECK, handleUpdateCheck, 0 } 166 166 }; 167 167 -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
r85683 r85778 110 110 USAGE_USBDEVSOURCE, 111 111 USAGE_CLOUDPROFILE, 112 USAGE_UPDATECHECK,113 112 /* Insert new entries before this line, but only if it is not an option 114 113 * to go for the new style command and help handling (see e.g. extpack, -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r85769 r85778 1239 1239 } 1240 1240 1241 if (enmCommand == USAGE_UPDATECHECK || enmCommand == USAGE_S_ALL)1242 {1243 RTStrmPrintf(pStrm,1244 "%s updatecheck %s perform\n"1245 "%s updatecheck %s getsettings\n"1246 "%s updatecheck %s modifysettings [--enable|--disable]\n"1247 " [--target=stable|withbetas|allreleases]\n"1248 " [--frequency=<days>]\n"1249 "\n", SEP, SEP, SEP);1250 }1251 1252 1241 #ifndef VBOX_ONLY_DOCS /* Converted to man page, not needed. */ 1253 1242 if (enmCommand == USAGE_S_ALL) -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageUpdateCheck.cpp
r85688 r85778 41 41 using namespace com; // SafeArray 42 42 43 // display all of the VBoxUpdate settings 43 /** 44 * updatecheck getsettings 45 */ 44 46 static RTEXITCODE doVBoxUpdateGetSettings(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox) 45 47 { 48 /* 49 * Parse options. 50 */ 51 static const RTGETOPTDEF s_aOptions[] = 52 { 53 { "--verbose", 'v', RTGETOPT_REQ_NOTHING } 54 }; 55 RTGETOPTSTATE GetState; 56 int vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0 /* First */, 0); 57 AssertRCReturn(vrc, RTEXITCODE_INIT); 58 46 59 int c; 47 60 RTGETOPTUNION ValueUnion; 48 RTGETOPTSTATE GetState;49 /** @todo r=brent decide on the best approach for options to specify here */50 static const RTGETOPTDEF s_aOptions[] =51 {52 { "--verbose", 'v', RTGETOPT_REQ_NOTHING }53 };54 int vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0 /* First */, 0);55 AssertRCReturn(vrc, RTEXITCODE_INIT);56 57 61 while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0) 58 62 { 59 63 switch (c) 60 64 { 61 case 'h':62 printUsage(USAGE_UPDATECHECK, RTMSGREFENTRYSTR_SCOPE_GLOBAL, g_pStdOut);63 return RTEXITCODE_SUCCESS;64 65 65 default: 66 return errorGetOpt( USAGE_UPDATECHECK,c, &ValueUnion);66 return errorGetOpt(c, &ValueUnion); 67 67 } 68 68 } 69 69 70 if (argc != 0)71 return errorSyntax(USAGE_UPDATECHECK, "Incorrect number of parameters");72 70 /* 71 * Do the work. 72 */ 73 73 ComPtr<ISystemProperties> pSystemProperties; 74 74 CHECK_ERROR2I_RET(aVirtualBox, COMGETTER(SystemProperties)(pSystemProperties.asOutParam()), RTEXITCODE_FAILURE); … … 97 97 { 98 98 case VBoxUpdateTarget_Stable: 99 psz = "Stable :new minor and maintenance releases";99 psz = "Stable - new minor and maintenance releases"; 100 100 break; 101 101 case VBoxUpdateTarget_AllReleases: 102 psz = "All releases :new minor, maintenance, and major releases";102 psz = "All releases - new minor, maintenance, and major releases"; 103 103 break; 104 104 case VBoxUpdateTarget_WithBetas: 105 psz = "With Betas :new minor, maintenance, major, and beta releases";105 psz = "With Betas - new minor, maintenance, major, and beta releases"; 106 106 break; 107 107 default: … … 120 120 } 121 121 122 /** 123 * updatecheck modifysettings 124 */ 122 125 static RTEXITCODE doVBoxUpdateModifySettings(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox) 123 126 { 124 BOOL fEnableVBoxUpdate = false; 125 BOOL fDisableVBoxUpdate = false; 126 const char *pszVBoxUpdateTarget = NULL; 127 uint32_t uVBoxUpdateFrequency = 0; 127 /* 128 * Parse options. 129 */ 130 static const RTGETOPTDEF s_aOptions[] = 131 { 132 { "--enable", 'e', RTGETOPT_REQ_NOTHING }, 133 { "--disable", 'd', RTGETOPT_REQ_NOTHING }, 134 { "--target", 't', RTGETOPT_REQ_STRING }, 135 { "--frequency", 'f', RTGETOPT_REQ_UINT32 }, 136 }; 137 138 RTGETOPTSTATE GetState; 139 int vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0 /* First */, 0); 140 AssertRCReturn(vrc, RTEXITCODE_INIT); 141 142 int fEnabled = -1; /* tristate: -1 (not modified), false, true */ 143 VBoxUpdateTarget_T const enmVBoxUpdateTargetNil = (VBoxUpdateTarget_T)-999; 144 VBoxUpdateTarget_T enmVBoxUpdateTarget = enmVBoxUpdateTargetNil; 145 uint32_t cDaysUpdateFrequency = 0; 128 146 129 147 int c; 130 148 RTGETOPTUNION ValueUnion; 149 while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0) 150 { 151 switch (c) 152 { 153 case 'e': 154 fEnabled = true; 155 break; 156 157 case 'd': 158 fEnabled = false; 159 break; 160 161 case 't': 162 if (!RTStrICmp(ValueUnion.psz, "stable")) 163 enmVBoxUpdateTarget = VBoxUpdateTarget_Stable; 164 else if (!RTStrICmp(ValueUnion.psz, "withbetas")) 165 enmVBoxUpdateTarget = VBoxUpdateTarget_WithBetas; 166 else if (!RTStrICmp(ValueUnion.psz, "allreleases")) 167 enmVBoxUpdateTarget = VBoxUpdateTarget_AllReleases; 168 else 169 return errorArgument("Unknown target specified: '%s'", ValueUnion.psz); 170 break; 171 172 case 'f': 173 cDaysUpdateFrequency = ValueUnion.u32; 174 if (cDaysUpdateFrequency == 0) 175 return errorArgument("The update frequency cannot be zero"); 176 break; 177 178 default: 179 return errorGetOpt(c, &ValueUnion); 180 } 181 } 182 183 if ( fEnabled == -1 184 && enmVBoxUpdateTarget != enmVBoxUpdateTargetNil 185 && cDaysUpdateFrequency == 0) 186 return errorSyntax("No change requested"); 187 188 /* 189 * Make the changes. 190 */ 191 ComPtr<ISystemProperties> pSystemProperties; 192 CHECK_ERROR2I_RET(aVirtualBox, COMGETTER(SystemProperties)(pSystemProperties.asOutParam()), RTEXITCODE_FAILURE); 193 194 if (enmVBoxUpdateTarget != enmVBoxUpdateTargetNil) 195 { 196 CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateTarget)(enmVBoxUpdateTarget), RTEXITCODE_FAILURE); 197 } 198 199 if (fEnabled != -1) 200 { 201 CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateEnabled)((BOOL)fEnabled), RTEXITCODE_FAILURE); 202 } 203 204 if (cDaysUpdateFrequency) 205 { 206 CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateFrequency)(cDaysUpdateFrequency), RTEXITCODE_FAILURE); 207 } 208 209 return RTEXITCODE_SUCCESS; 210 } 211 212 /** 213 * updatecheck perform 214 */ 215 static RTEXITCODE doVBoxUpdate(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox) 216 { 217 /* 218 * Parse arguments. 219 */ 220 static const RTGETOPTDEF s_aOptions[] = 221 { 222 { "--verbose", 'v', RTGETOPT_REQ_NOTHING } 223 }; 131 224 RTGETOPTSTATE GetState; 132 133 # define UPDATECHECK_MODSETTING_ENABLE (VINF_GETOPT_NOT_OPTION + 'e')134 # define UPDATECHECK_MODSETTING_DISABLE (VINF_GETOPT_NOT_OPTION + 'd')135 # define UPDATECHECK_MODSETTING_TARGET (VINF_GETOPT_NOT_OPTION + 't')136 # define UPDATECHECK_MODSETTING_FREQUENCY (VINF_GETOPT_NOT_OPTION + 'f')137 138 static const RTGETOPTDEF s_aOptions[] =139 {140 { "--enable", UPDATECHECK_MODSETTING_ENABLE, RTGETOPT_REQ_NOTHING },141 { "--disable", UPDATECHECK_MODSETTING_DISABLE, RTGETOPT_REQ_NOTHING },142 { "--target", UPDATECHECK_MODSETTING_TARGET, RTGETOPT_REQ_STRING },143 { "--frequency", UPDATECHECK_MODSETTING_FREQUENCY, RTGETOPT_REQ_UINT32 },144 };145 225 int vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0 /* First */, 0); 146 226 AssertRCReturn(vrc, RTEXITCODE_INIT); 147 227 228 int c; 229 RTGETOPTUNION ValueUnion; 148 230 while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0) 149 231 { 150 232 switch (c) 151 233 { 152 case UPDATECHECK_MODSETTING_ENABLE:153 fEnableVBoxUpdate = true;154 break;155 156 case UPDATECHECK_MODSETTING_DISABLE:157 fDisableVBoxUpdate = true;158 break;159 160 case UPDATECHECK_MODSETTING_TARGET:161 pszVBoxUpdateTarget = ValueUnion.psz;162 break;163 164 case UPDATECHECK_MODSETTING_FREQUENCY:165 uVBoxUpdateFrequency = ValueUnion.u32;166 break;167 168 case 'h':169 printUsage(USAGE_UPDATECHECK, RTMSGREFENTRYSTR_SCOPE_GLOBAL, g_pStdOut);170 return RTEXITCODE_SUCCESS;171 172 234 default: 173 return errorGetOpt( USAGE_UPDATECHECK,c, &ValueUnion);235 return errorGetOpt(c, &ValueUnion); 174 236 } 175 237 } 176 238 177 if (argc == 0) 178 return errorSyntax(USAGE_UPDATECHECK, "Incorrect number of parameters"); 179 180 if (fEnableVBoxUpdate && fDisableVBoxUpdate) 181 return errorSyntax(USAGE_UPDATECHECK, "Invalid combination of options: --enable and --disable"); 182 183 ComPtr<ISystemProperties> pSystemProperties; 184 CHECK_ERROR2I_RET(aVirtualBox, COMGETTER(SystemProperties)(pSystemProperties.asOutParam()), RTEXITCODE_FAILURE); 185 186 if (pszVBoxUpdateTarget) 187 { 188 VBoxUpdateTarget_T enmVBoxUpdateTarget; 189 if (!RTStrICmp(pszVBoxUpdateTarget, "stable")) 190 enmVBoxUpdateTarget = VBoxUpdateTarget_Stable; 191 else if (!RTStrICmp(pszVBoxUpdateTarget, "withbetas")) 192 enmVBoxUpdateTarget = VBoxUpdateTarget_WithBetas; 193 else if (!RTStrICmp(pszVBoxUpdateTarget, "allreleases")) 194 enmVBoxUpdateTarget = VBoxUpdateTarget_AllReleases; 195 else 196 return errorArgument("Unknown target specified: '%s'", pszVBoxUpdateTarget); 197 198 CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateTarget)(enmVBoxUpdateTarget), RTEXITCODE_FAILURE); 199 } 200 201 if (fEnableVBoxUpdate) 202 { 203 CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateEnabled)(true), RTEXITCODE_FAILURE); 204 } 205 else if (fDisableVBoxUpdate) 206 { 207 CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateEnabled)(false), RTEXITCODE_FAILURE); 208 } 209 210 if (uVBoxUpdateFrequency) 211 { 212 CHECK_ERROR2I_RET(pSystemProperties, COMSETTER(VBoxUpdateFrequency)(uVBoxUpdateFrequency), RTEXITCODE_FAILURE); 213 } 214 215 return RTEXITCODE_SUCCESS; 216 } 217 218 static RTEXITCODE doVBoxUpdate(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox) 219 { 220 int c; 221 RTGETOPTUNION ValueUnion; 222 RTGETOPTSTATE GetState; 223 /** @todo r=brent decide on the best approach for options to specify here */ 224 static const RTGETOPTDEF s_aOptions[] = 225 { 226 { "--verbose", 'v', RTGETOPT_REQ_NOTHING } 227 }; 228 int vrc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 0 /* First */, 0); 229 AssertRCReturn(vrc, RTEXITCODE_INIT); 230 231 while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0) 232 { 233 switch (c) 234 { 235 case 'h': 236 printUsage(USAGE_UPDATECHECK, RTMSGREFENTRYSTR_SCOPE_GLOBAL, g_pStdOut); 237 return RTEXITCODE_SUCCESS; 238 239 default: 240 return errorGetOpt(USAGE_UPDATECHECK, c, &ValueUnion); 241 } 242 } 243 239 /* 240 * Do the work. 241 */ 244 242 ComPtr<IHost> pHost; 245 243 CHECK_ERROR2I_RET(aVirtualBox, COMGETTER(Host)(pHost.asOutParam()), RTEXITCODE_FAILURE); … … 249 247 250 248 UpdateCheckType_T updateCheckType = UpdateCheckType_VirtualBox; 251 BOOL updateNeeded; 252 ComPtr<IProgress> progress; 249 ComPtr<IProgress> ptrProgress; 253 250 254 251 RTPrintf("Checking for a new VirtualBox version...\n"); … … 256 253 // we don't call CHECK_ERROR2I_RET(pHostUpdate, VBoxUpdate(updateCheckType, ...); here so we can check for a specific 257 254 // return value indicating update checks are disabled. 258 HRESULT rc = pHostUpdate->UpdateCheck(updateCheckType, p rogress.asOutParam());255 HRESULT rc = pHostUpdate->UpdateCheck(updateCheckType, ptrProgress.asOutParam()); 259 256 if (FAILED(rc)) 260 257 { 258 /** @todo r=bird: WTF? This makes no sense. I've commented upon this in the 259 * HostUpdateImpl.cpp code too. */ 261 260 if (rc == E_NOTIMPL) 262 261 { … … 265 264 } 266 265 267 if (p rogress.isNull())268 RTStrmPrintf(g_pStdErr, "Failed to create p rogress object: %Rhrc\n", rc);266 if (ptrProgress.isNull()) 267 RTStrmPrintf(g_pStdErr, "Failed to create ptrProgress object: %Rhrc\n", rc); 269 268 else 270 com::GlueHandleComError(pHostUpdate, "VBoxUpdate(updateCheckType, progress.asOutParam())", rc, 271 __FILE__, __LINE__); 269 com::GlueHandleComError(pHostUpdate, "VBoxUpdate(updateCheckType, ptrProgress.asOutParam())", rc, __FILE__, __LINE__); 272 270 return RTEXITCODE_FAILURE; 273 271 } 274 272 275 /* HRESULT hrc = */ showProgress(p rogress);276 CHECK_PROGRESS_ERROR_RET(p rogress, ("Check for update failed."), RTEXITCODE_FAILURE);277 278 CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateResponse)(&updateNeeded), RTEXITCODE_FAILURE);279 280 if (!updateNeeded) 281 {273 /* HRESULT hrc = */ showProgress(ptrProgress); 274 CHECK_PROGRESS_ERROR_RET(ptrProgress, ("Check for update failed."), RTEXITCODE_FAILURE); 275 276 BOOL fUpdateNeeded = FALSE; 277 CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateResponse)(&fUpdateNeeded), RTEXITCODE_FAILURE); 278 279 if (!fUpdateNeeded) 282 280 RTPrintf("You are already running the most recent version of VirtualBox.\n"); 283 }284 281 else 285 282 { 286 Bstr updateVersion; 287 Bstr updateURL; 288 289 CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateVersion)(updateVersion.asOutParam()), RTEXITCODE_FAILURE); 290 CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateURL)(updateURL.asOutParam()), RTEXITCODE_FAILURE); 291 292 RTPrintf("A new version of VirtualBox has been released! Version %ls is available " 293 "at virtualbox.org.\nYou can download this version here: %ls\n", updateVersion.raw(), updateURL.raw()); 283 Bstr bstrUpdateVersion; 284 CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateVersion)(bstrUpdateVersion.asOutParam()), RTEXITCODE_FAILURE); 285 Bstr bstrUpdateURL; 286 CHECK_ERROR2I_RET(pHostUpdate, COMGETTER(UpdateURL)(bstrUpdateURL.asOutParam()), RTEXITCODE_FAILURE); 287 288 RTPrintf("A new version of VirtualBox has been released! Version %ls is available at virtualbox.org.\n" 289 "You can download this version here: %ls\n", bstrUpdateVersion.raw(), bstrUpdateURL.raw()); 294 290 } 295 291 … … 305 301 RTEXITCODE handleUpdateCheck(HandlerArg *a) 306 302 { 303 if (a->argc < 1) 304 return errorNoSubcommand(); 307 305 if (!strcmp(a->argv[0], "perform")) 308 306 { 309 // VBoxManage updatecheck307 setCurrentSubcommand(HELP_SCOPE_UPDATECHECK_PERFORM); 310 308 return doVBoxUpdate(a->argc - 1, &a->argv[1], a->virtualBox); 311 309 } 312 elseif (!strcmp(a->argv[0], "getsettings"))313 { 314 // VBoxManage updatecheck getsettings310 if (!strcmp(a->argv[0], "getsettings")) 311 { 312 setCurrentSubcommand(HELP_SCOPE_UPDATECHECK_GETSETTINGS); 315 313 return doVBoxUpdateGetSettings(a->argc - 1, &a->argv[1], a->virtualBox); 316 314 } 317 elseif (!strcmp(a->argv[0], "modifysettings"))318 { 319 // VBoxManage updatecheck modifysettings key=value315 if (!strcmp(a->argv[0], "modifysettings")) 316 { 317 setCurrentSubcommand(HELP_SCOPE_UPDATECHECK_MODIFYSETTINGS); 320 318 return doVBoxUpdateModifySettings(a->argc - 1, &a->argv[1], a->virtualBox); 321 319 } 322 else 323 { 324 printUsage(USAGE_UPDATECHECK, RTMSGREFENTRYSTR_SCOPE_GLOBAL, g_pStdOut); 325 return RTEXITCODE_FAILURE; 326 } 320 return errorUnknownSubcommand(a->argv[0]); 327 321 } 328 322
Note:
See TracChangeset
for help on using the changeset viewer.