mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
setup: add --help and --no_dotnet commands
This commit is contained in:
committed by
Andrey Nekrasov
parent
4e969a3701
commit
870f1095cd
@@ -9,7 +9,6 @@
|
|||||||
#include <common/appMutex.h>
|
#include <common/appMutex.h>
|
||||||
#include <common/processApi.h>
|
#include <common/processApi.h>
|
||||||
|
|
||||||
|
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
|
|
||||||
#include <runner/action_runner_utils.h>
|
#include <runner/action_runner_utils.h>
|
||||||
@@ -64,12 +63,24 @@ enum class CmdArgs
|
|||||||
{
|
{
|
||||||
silent,
|
silent,
|
||||||
noFullUI,
|
noFullUI,
|
||||||
noStartPT
|
noStartPT,
|
||||||
|
skipDotnetInstall,
|
||||||
|
showHelp
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
const std::unordered_map<std::wstring_view, CmdArgs> knownArgs = {
|
||||||
|
{ L"--help", CmdArgs::showHelp },
|
||||||
|
{ L"--no_full_ui", CmdArgs::noFullUI },
|
||||||
|
{ L"--silent", CmdArgs::silent },
|
||||||
|
{ L"--no_start_pt", CmdArgs::noStartPT },
|
||||||
|
{ L"--skip_dotnet_install", CmdArgs::skipDotnetInstall }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
std::unordered_set<CmdArgs> parseCmdArgs(const int nCmdArgs, LPWSTR* argList)
|
std::unordered_set<CmdArgs> parseCmdArgs(const int nCmdArgs, LPWSTR* argList)
|
||||||
{
|
{
|
||||||
const std::unordered_map<std::wstring_view, CmdArgs> knownArgs = { { L"--no_full_ui", CmdArgs::noFullUI }, { L"--silent", CmdArgs::silent }, { L"--no_start_pt", CmdArgs::noStartPT } };
|
|
||||||
std::unordered_set<CmdArgs> result;
|
std::unordered_set<CmdArgs> result;
|
||||||
for (size_t i = 1; i < nCmdArgs; ++i)
|
for (size_t i = 1; i < nCmdArgs; ++i)
|
||||||
{
|
{
|
||||||
@@ -80,7 +91,6 @@ std::unordered_set<CmdArgs> parseCmdArgs(const int nCmdArgs, LPWSTR* argList)
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
||||||
{
|
{
|
||||||
using namespace localized_strings;
|
using namespace localized_strings;
|
||||||
@@ -89,6 +99,17 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
|||||||
int nCmdArgs = 0;
|
int nCmdArgs = 0;
|
||||||
LPWSTR* argList = CommandLineToArgvW(GetCommandLineW(), &nCmdArgs);
|
LPWSTR* argList = CommandLineToArgvW(GetCommandLineW(), &nCmdArgs);
|
||||||
const auto cmdArgs = parseCmdArgs(nCmdArgs, argList);
|
const auto cmdArgs = parseCmdArgs(nCmdArgs, argList);
|
||||||
|
std::wostringstream oss;
|
||||||
|
if (cmdArgs.contains(CmdArgs::showHelp))
|
||||||
|
{
|
||||||
|
oss << "Supported arguments:\n\n";
|
||||||
|
for (auto [arg, _] : knownArgs)
|
||||||
|
{
|
||||||
|
oss << arg << '\n';
|
||||||
|
}
|
||||||
|
MessageBoxW(nullptr, oss.str().c_str(), L"Help", MB_OK | MB_ICONINFORMATION);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (!cmdArgs.contains(CmdArgs::noFullUI))
|
if (!cmdArgs.contains(CmdArgs::noFullUI))
|
||||||
{
|
{
|
||||||
MsiSetInternalUI(INSTALLUILEVEL_FULL, nullptr);
|
MsiSetInternalUI(INSTALLUILEVEL_FULL, nullptr);
|
||||||
@@ -231,16 +252,24 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
|||||||
{
|
{
|
||||||
notifications::show_toast(UNINSTALL_PREVIOUS_VERSION_ERROR, TOAST_TITLE);
|
notifications::show_toast(UNINSTALL_PREVIOUS_VERSION_ERROR, TOAST_TITLE);
|
||||||
}
|
}
|
||||||
|
const bool installDotnet = !cmdArgs.contains(CmdArgs::skipDotnetInstall);
|
||||||
updateProgressBar(.5f, INSTALLING_DOTNET);
|
if (installDotnet)
|
||||||
if (!updating::dotnet_is_installed() && !updating::install_dotnet() && !cmdArgs.contains(CmdArgs::silent))
|
{
|
||||||
|
updateProgressBar(.5f, INSTALLING_DOTNET);
|
||||||
|
}
|
||||||
|
if (installDotnet &&
|
||||||
|
!updating::dotnet_is_installed() &&
|
||||||
|
!updating::install_dotnet(cmdArgs.contains(CmdArgs::silent)) &&
|
||||||
|
!cmdArgs.contains(CmdArgs::silent))
|
||||||
{
|
{
|
||||||
notifications::show_toast(DOTNET_INSTALL_ERROR, TOAST_TITLE);
|
notifications::show_toast(DOTNET_INSTALL_ERROR, TOAST_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateProgressBar(.75f, INSTALLING_NEW_VERSION);
|
updateProgressBar(.75f, INSTALLING_NEW_VERSION);
|
||||||
|
|
||||||
const bool installationDone = MsiInstallProductW(installerPath->c_str(), nullptr) == ERROR_SUCCESS;
|
// Always skip dotnet install, because we should've installed it from here earlier
|
||||||
|
std::wstring msiProps = L"SKIPDOTNETINSTALL=1 ";
|
||||||
|
const bool installationDone = MsiInstallProductW(installerPath->c_str(), msiProps.c_str()) == ERROR_SUCCESS;
|
||||||
updateProgressBar(1.f, installationDone ? NEW_VERSION_INSTALLATION_DONE : NEW_VERSION_INSTALLATION_ERROR);
|
updateProgressBar(1.f, installationDone ? NEW_VERSION_INSTALLATION_DONE : NEW_VERSION_INSTALLATION_ERROR);
|
||||||
if (!installationDone)
|
if (!installationDone)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,3 +11,5 @@
|
|||||||
#include <Msi.h>
|
#include <Msi.h>
|
||||||
|
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <tuple>
|
||||||
|
#include <sstream>
|
||||||
|
|||||||
@@ -70,7 +70,8 @@
|
|||||||
<Property Id="INSTALLSTARTMENUSHORTCUT" Value="1"/>
|
<Property Id="INSTALLSTARTMENUSHORTCUT" Value="1"/>
|
||||||
<Property Id="CREATESCHEDULEDTASK" Value="1"/>
|
<Property Id="CREATESCHEDULEDTASK" Value="1"/>
|
||||||
<Property Id="WixShellExecTarget" Value="[#action_runner.exe]" />
|
<Property Id="WixShellExecTarget" Value="[#action_runner.exe]" />
|
||||||
|
<Property Id="SKIPDOTNETINSTALL" Value="0"/>
|
||||||
|
|
||||||
<Property Id ="EXISTINGPOWERRENAMEEXTPATH">
|
<Property Id ="EXISTINGPOWERRENAMEEXTPATH">
|
||||||
<RegistrySearch Id="ExistingExtPath" Root="HKCR" Key="CLSID\{0440049F-D1DC-4E46-B27B-98393D79486B}\InprocServer32" Type="raw"/>
|
<RegistrySearch Id="ExistingExtPath" Root="HKCR" Key="CLSID\{0440049F-D1DC-4E46-B27B-98393D79486B}\InprocServer32" Type="raw"/>
|
||||||
</Property>
|
</Property>
|
||||||
@@ -96,7 +97,7 @@
|
|||||||
</Custom>
|
</Custom>
|
||||||
|
|
||||||
<Custom Action="InstallDotNet" After="InstallFinalize">
|
<Custom Action="InstallDotNet" After="InstallFinalize">
|
||||||
NOT Installed
|
NOT Installed and (SKIPDOTNETINSTALL = 0)
|
||||||
</Custom>
|
</Custom>
|
||||||
|
|
||||||
<Custom Action="TerminateProcesses" Before="InstallValidate" />
|
<Custom Action="TerminateProcesses" Before="InstallValidate" />
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace updating
|
|||||||
return runtimes->find(DESKTOP_DOTNET_RUNTIME_STRING) != std::string::npos;
|
return runtimes->find(DESKTOP_DOTNET_RUNTIME_STRING) != std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool install_dotnet()
|
bool install_dotnet(const bool silent)
|
||||||
{
|
{
|
||||||
const wchar_t DOTNET_DESKTOP_DOWNLOAD_LINK[] = L"https://download.visualstudio.microsoft.com/download/pr/3eb7efa1-96c6-4e97-bb9f-563ecf595f8a/7efd9c1cdd74df8fb0a34c288138a84f/windowsdesktop-runtime-3.1.6-win-x64.exe";
|
const wchar_t DOTNET_DESKTOP_DOWNLOAD_LINK[] = L"https://download.visualstudio.microsoft.com/download/pr/3eb7efa1-96c6-4e97-bb9f-563ecf595f8a/7efd9c1cdd74df8fb0a34c288138a84f/windowsdesktop-runtime-3.1.6-win-x64.exe";
|
||||||
const wchar_t DOTNET_DESKTOP_FILENAME[] = L"windowsdesktop-runtime.exe";
|
const wchar_t DOTNET_DESKTOP_FILENAME[] = L"windowsdesktop-runtime.exe";
|
||||||
@@ -52,7 +52,9 @@ namespace updating
|
|||||||
sei.fMask = { SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE };
|
sei.fMask = { SEE_MASK_NOASYNC | SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NO_CONSOLE };
|
||||||
sei.lpFile = dotnet_download_path.c_str();
|
sei.lpFile = dotnet_download_path.c_str();
|
||||||
sei.nShow = SW_SHOWNORMAL;
|
sei.nShow = SW_SHOWNORMAL;
|
||||||
sei.lpParameters = L"/install /passive";
|
std::wstring dotnet_flags = L"/install ";
|
||||||
|
dotnet_flags += silent ? L"/quiet" : L"/passive";
|
||||||
|
sei.lpParameters = dotnet_flags.c_str();
|
||||||
if (ShellExecuteExW(&sei) != TRUE)
|
if (ShellExecuteExW(&sei) != TRUE)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -3,5 +3,5 @@
|
|||||||
namespace updating
|
namespace updating
|
||||||
{
|
{
|
||||||
bool dotnet_is_installed();
|
bool dotnet_is_installed();
|
||||||
bool install_dotnet();
|
bool install_dotnet(const bool silent = false);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user