VirtualBox

Changeset 93390 in vbox for trunk/src


Ignore:
Timestamp:
Jan 21, 2022 9:26:43 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
149485
Message:

Installer/win: Documented proper quoting of --msiparams, adding a --msi-props <prop> <value> option for simplifying this. Changed to exit with RTEXITCODE_SYNTAX on syntax error. bugref:10164

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/win/Stub/VBoxStub.cpp

    r93115 r93390  
    145145    va_end(va);
    146146    return RTEXITCODE_FAILURE;
     147}
     148
     149
     150/**
     151 * Same as ShowError, only it returns RTEXITCODE_SYNTAX.
     152 */
     153static RTEXITCODE ShowSyntaxError(const char *pszFmt, ...)
     154{
     155    va_list va;
     156    va_start(va, pszFmt);
     157    ShowError("%N", pszFmt, &va);
     158    va_end(va);
     159    return RTEXITCODE_SYNTAX;
    147160}
    148161
     
    908921        { "--msiparams",        'm', RTGETOPT_REQ_STRING  },
    909922        { "-msiparams",         'm', RTGETOPT_REQ_STRING  },
     923        { "--msi-prop",         'P', RTGETOPT_REQ_STRING  },
    910924        { "--reinstall",        'f', RTGETOPT_REQ_NOTHING },
    911925        { "-reinstall",         'f', RTGETOPT_REQ_NOTHING },
     
    918932        { "-version",           'V', RTGETOPT_REQ_NOTHING },
    919933        { "/version",           'V', RTGETOPT_REQ_NOTHING },
    920         { "-v",                 'V', RTGETOPT_REQ_NOTHING },
    921934        { "--help",             'h', RTGETOPT_REQ_NOTHING },
    922935        { "-help",              'h', RTGETOPT_REQ_NOTHING },
     
    946959                                   "REINSTALLMODE=vomus REINSTALL=ALL");
    947960                if (RT_FAILURE(vrc))
    948                     rcExit = ShowError("MSI parameters are too long.");
     961                    rcExit = ShowSyntaxError("Out of space for MSI parameters and properties");
    949962                break;
    950963
     
    969982                vrc = RTStrCopy(szExtractPath, sizeof(szExtractPath), ValueUnion.psz);
    970983                if (RT_FAILURE(vrc))
    971                     rcExit = ShowError("Extraction path is too long.");
     984                    rcExit = ShowSyntaxError("Extraction path is too long.");
    972985                break;
    973986
     
    978991                    vrc = RTStrCat(szMSIArgs, sizeof(szMSIArgs), ValueUnion.psz);
    979992                if (RT_FAILURE(vrc))
    980                     rcExit = ShowError("MSI parameters are too long.");
     993                    rcExit = ShowSyntaxError("Out of space for MSI parameters and properties");
    981994                break;
     995
     996            case 'P':
     997            {
     998                const char *pszProp = ValueUnion.psz;
     999                if (strpbrk(pszProp, " \t\n\r") == NULL)
     1000                {
     1001                    vrc = RTGetOptFetchValue(&GetState, &ValueUnion, RTGETOPT_REQ_STRING);
     1002                    if (RT_SUCCESS(vrc))
     1003                    {
     1004                        size_t cchMsiArgs = strlen(szMSIArgs);
     1005                        if (RTStrPrintf2(&szMSIArgs[cchMsiArgs], sizeof(szMSIArgs) - cchMsiArgs,
     1006                                         strpbrk(ValueUnion.psz, " \t\n\r") == NULL ? "%s%s=%s" : "%s%s=\"%s\"",
     1007                                         cchMsiArgs ? " " : "", pszProp, ValueUnion.psz) <= 1)
     1008                            rcExit = ShowSyntaxError("Out of space for MSI parameters and properties");
     1009                    }
     1010                    else if (vrc == VERR_GETOPT_REQUIRED_ARGUMENT_MISSING)
     1011                        rcExit = ShowSyntaxError("--msi-prop takes two arguments, the 2nd is missing");
     1012                    else
     1013                        rcExit = ShowSyntaxError("Failed to get 2nd --msi-prop argument: %Rrc", vrc);
     1014                }
     1015                else
     1016                    rcExit = ShowSyntaxError("The first argument to --msi-prop must not contain spaces: %s", pszProp);
     1017                break;
     1018            }
    9821019
    9831020            case 'r':
     
    9861023
    9871024            case 'V':
    988                 ShowInfo("Version: %d.%d.%d.%d",
    989                          VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD,
    990                          VBOX_SVN_REV);
     1025                ShowInfo("Version: %u.%u.%ur%u", VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV);
    9911026                fExitEarly = true;
    9921027                break;
     
    9971032
    9981033            case 'h':
    999                 ShowInfo("-- %s v%d.%d.%d.%d --\n"
     1034                ShowInfo("-- %s v%u.%u.%ur%u --\n"
    10001035                         "\n"
    10011036                         "Command Line Parameters:\n\n"
    1002                          "--extract                - Extract file contents to temporary directory\n"
    1003                          "--help                   - Print this help and exit\n"
    1004                          "--logging                - Enables installer logging\n"
    1005                          "--msiparams <parameters> - Specifies extra parameters for the MSI installers\n"
    1006                          "--no-silent-cert         - Do not install VirtualBox Certificate automatically when --silent option is specified\n"
    1007                          "--path                   - Sets the path of the extraction directory\n"
    1008                          "--reinstall              - Forces VirtualBox to get re-installed\n"
    1009                          "--ignore-reboot          - Don't set exit code to 3010 if a reboot is required\n"
    1010                          "--silent                 - Enables silent mode installation\n"
    1011                          "--version                - Print version number and exit\n"
     1037                         "--extract\n"
     1038                         "    Extract file contents to temporary directory\n"
     1039                         "--logging\n"
     1040                         "    Enables installer logging\n"
     1041                         "--msiparams <parameters>\n"
     1042                         "    Specifies extra parameters for the MSI installers\n"
     1043                         "    double quoted arguments must be doubled and put\n"
     1044                         "    in quotes: --msiparams \"PROP=\"\"a b c\"\"\"\n"
     1045                         "--msi-prop <prop> <value>\n"
     1046                         "    Adds <prop>=<value> to the MSI parameters,\n"
     1047                         "    quoting the property value if necessary\n"
     1048                         "--no-silent-cert\n"
     1049                         "    Do not install VirtualBox Certificate automatically\n"
     1050                         "    when --silent option is specified\n"
     1051                         "--path\n"
     1052                         "    Sets the path of the extraction directory\n"
     1053                         "--reinstall\n"
     1054                         "    Forces VirtualBox to get re-installed\n"
     1055                         "--ignore-reboot\n"
     1056                         "   Do not set exit code to 3010 if a reboot is required\n"
     1057                         "--silent\n"
     1058                         "   Enables silent mode installation\n"
     1059                         "--version\n"
     1060                         "   Displays version number and exit\n"
     1061                         "-?, -h, --help\n"
     1062                         "   Displays this help text and exit\n"
    10121063                         "\n"
    10131064                         "Examples:\n"
    1014                          "%s --msiparams INSTALLDIR=C:\\VBox\n"
    1015                          "%s --extract -path C:\\VBox",
     1065                         "  %s --msiparams \"INSTALLDIR=\"\"C:\\Program Files\\VirtualBox\"\"\"\n"
     1066                         "  %s --extract -path C:\\VBox",
    10161067                         VBOX_STUB_TITLE, VBOX_VERSION_MAJOR, VBOX_VERSION_MINOR, VBOX_VERSION_BUILD, VBOX_SVN_REV,
    10171068                         argv[0], argv[0]);
     
    10221073                /* Are (optional) MSI parameters specified and this is the last
    10231074                 * parameter? Append everything to the MSI parameter list then. */
     1075                /** @todo r=bird: this makes zero sense */
    10241076                if (szMSIArgs[0])
    10251077                {
     
    10281080                        vrc = RTStrCat(szMSIArgs, sizeof(szMSIArgs), ValueUnion.psz);
    10291081                    if (RT_FAILURE(vrc))
    1030                         rcExit = ShowError("MSI parameters are too long.");
     1082                        rcExit = ShowSyntaxError("Out of space for MSI parameters and properties");
    10311083                    continue;
    10321084                }
     
    10371089                    rcExit = RTGetOptPrintError(ch, &ValueUnion);
    10381090                if (ch == VERR_GETOPT_UNKNOWN_OPTION)
    1039                     rcExit = ShowError("Unknown option \"%s\"\n"
    1040                                        "Please refer to the command line help by specifying \"/?\"\n"
    1041                                        "to get more information.", ValueUnion.psz);
     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);
    10421094                else
    1043                     rcExit = ShowError("Parameter parsing error: %Rrc\n"
    1044                                        "Please refer to the command line help by specifying \"/?\"\n"
    1045                                        "to get more information.", ch);
     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);
    10461098                break;
    10471099        }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette