Adds uwptool install command (flutter/engine#26183)

Installs the package pointed to by a URI, as well as its dependencies.
This commit is contained in:
Chris Bracken
2021-05-16 11:15:48 -07:00
committed by GitHub
parent 0314ee2579
commit fcbf9016d5
3 changed files with 70 additions and 5 deletions

View File

@@ -42,6 +42,19 @@ int LaunchApp(const std::wstring_view package_family,
return -1;
}
// Installs the app in the specified build output directory.
//
// Returns true on success.
bool InstallApp(const std::wstring_view package_uri,
const std::vector<std::wstring>& dependency_uris) {
flutter::ApplicationStore app_store;
if (app_store.InstallApp(package_uri, dependency_uris)) {
std::wcerr << L"Installed application " << package_uri << std::endl;
return true;
}
return false;
}
// Uninstalls the app with the specified package.
//
// Returns true on success.
@@ -63,11 +76,12 @@ bool UninstallApp(const std::wstring_view package_family) {
// Prints the command usage to stderr.
void PrintUsage() {
std::cerr << "usage: uwptool COMMAND [ARGUMENTS]" << std::endl;
std::cerr << "commands:" << std::endl;
std::cerr << " listapps list installed apps" << std::endl;
std::cerr << " launch PACKAGE_FAMILY launch an app" << std::endl;
std::cerr << " uninstall PACKAGE_FAMILY uninstall an app" << std::endl;
std::cerr << "usage: uwptool COMMAND [ARGUMENTS]" << std::endl
<< "commands:" << std::endl
<< " listapps list all apps" << std::endl
<< " launch PACKAGE_FAMILY launch an app" << std::endl
<< " install PACKAGE_URI DEP_URI... install an app" << std::endl
<< " uninstall PACKAGE_FAMILY uninstall an app" << std::endl;
}
} // namespace
@@ -117,6 +131,17 @@ int main(int argc, char** argv) {
// Write the PID to stdout. The flutter tool reads this value in.
std::cout << process_id << std::endl;
return 0;
} else if (command == "install") {
if (args.size() < 2) {
PrintUsage();
return 1;
}
std::wstring package_uri = flutter::Utf16FromUtf8(args[1]);
std::vector<std::wstring> dependency_uris;
for (int i = 2; i < args.size(); ++i) {
dependency_uris.push_back(flutter::Utf16FromUtf8(args[i]));
}
return InstallApp(package_uri, dependency_uris) ? 0 : 1;
} else if (command == "uninstall") {
if (args.size() < 2) {
PrintUsage();

View File

@@ -112,4 +112,37 @@ std::vector<Application> ApplicationStore::GetApps(
return apps;
}
bool ApplicationStore::InstallApp(
const std::wstring_view package_uri,
const std::vector<std::wstring>& dependency_uris) {
using winrt::Windows::Foundation::AsyncStatus;
using winrt::Windows::Foundation::Uri;
using winrt::Windows::Foundation::Collections::IVector;
using winrt::Windows::Management::Deployment::DeploymentOptions;
using winrt::Windows::Management::Deployment::PackageManager;
Uri package(package_uri);
IVector<Uri> dependencies = winrt::single_threaded_vector<Uri>();
for (const auto& dependency_uri : dependency_uris) {
dependencies.Append(Uri(dependency_uri));
}
PackageManager package_manager;
auto operation = package_manager.AddPackageAsync(package, dependencies,
DeploymentOptions::None);
operation.get();
if (operation.Status() == AsyncStatus::Completed) {
return true;
} else if (operation.Status() == AsyncStatus::Canceled) {
return false;
} else if (operation.Status() == AsyncStatus::Error) {
auto result = operation.GetResults();
std::wcerr << L"error: install failed for package " << package_uri
<< L" with error: " << result.ErrorText().c_str() << std::endl;
return false;
}
return false;
}
} // namespace flutter

View File

@@ -70,6 +70,13 @@ class ApplicationStore {
// Returns all installed applications with the specified family name.
std::vector<Application> GetApps(
const std::wstring_view package_family) const;
// Installs the specified application.
//
// Installs the application located at package_uri with the specified
// dependencies.
bool InstallApp(const std::wstring_view package_uri,
const std::vector<std::wstring>& dependency_uris);
};
} // namespace flutter