mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
common project localization: move out all updating strings
- finish localizing boostrapper/runner/action_runner
This commit is contained in:
committed by
Andrey Nekrasov
parent
5629e8068b
commit
f33b3c771a
@@ -85,22 +85,22 @@ std::optional<std::wstring> get_last_error_message(const DWORD dw)
|
||||
return message;
|
||||
}
|
||||
|
||||
void show_last_error_message(LPCWSTR lpszFunction, DWORD dw, LPCWSTR errorTitle)
|
||||
void show_last_error_message(LPCWSTR functionName, DWORD dw, LPCWSTR errorTitle)
|
||||
{
|
||||
const auto system_message = get_last_error_message(dw);
|
||||
if (!system_message.has_value())
|
||||
{
|
||||
return;
|
||||
}
|
||||
LPWSTR lpDisplayBuf = (LPWSTR)LocalAlloc(LMEM_ZEROINIT, (system_message->size() + lstrlenW(lpszFunction) + 40) * sizeof(WCHAR));
|
||||
LPWSTR lpDisplayBuf = (LPWSTR)LocalAlloc(LMEM_ZEROINIT, (system_message->size() + lstrlenW(functionName) + 40) * sizeof(WCHAR));
|
||||
if (lpDisplayBuf != NULL)
|
||||
{
|
||||
StringCchPrintfW(lpDisplayBuf,
|
||||
LocalSize(lpDisplayBuf) / sizeof(WCHAR),
|
||||
localized_strings::LAST_ERROR_FORMAT_STRING,
|
||||
lpszFunction,
|
||||
dw,
|
||||
system_message->c_str());
|
||||
L"%s: %s (%d)",
|
||||
functionName,
|
||||
system_message->c_str(),
|
||||
dw);
|
||||
MessageBoxW(NULL, (LPCTSTR)lpDisplayBuf, errorTitle, MB_OK | MB_ICONERROR);
|
||||
LocalFree(lpDisplayBuf);
|
||||
}
|
||||
|
||||
@@ -7,12 +7,6 @@
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace localized_strings
|
||||
{
|
||||
const wchar_t LAST_ERROR_FORMAT_STRING[] = L"%s failed with error %d: %s";
|
||||
const wchar_t LAST_ERROR_TITLE_STRING[] = L"Error";
|
||||
}
|
||||
|
||||
// Gets position of given window.
|
||||
std::optional<RECT> get_window_pos(HWND hwnd);
|
||||
|
||||
@@ -23,7 +17,7 @@ bool is_system_window(HWND hwnd, const char* class_name);
|
||||
int run_message_loop(const bool until_idle = false, const std::optional<uint32_t> timeout_seconds = {});
|
||||
|
||||
std::optional<std::wstring> get_last_error_message(const DWORD dw);
|
||||
void show_last_error_message(LPCWSTR lpszFunction, DWORD dw, LPCWSTR errorTitle = localized_strings::LAST_ERROR_TITLE_STRING);
|
||||
void show_last_error_message(LPCWSTR lpszFunction, DWORD dw, LPCWSTR errorTitle);
|
||||
|
||||
enum WindowState
|
||||
{
|
||||
|
||||
@@ -33,8 +33,7 @@ using winrt::Windows::UI::Notifications::ToastNotificationManager;
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
// This namespace contains strings that SHOULD NOT be localized
|
||||
namespace
|
||||
namespace // Strings in this namespace should not be localized
|
||||
{
|
||||
constexpr std::wstring_view TASK_NAME = L"PowerToysBackgroundNotificationsHandler";
|
||||
constexpr std::wstring_view TASK_ENTRYPOINT = L"PowerToysNotifications.BackgroundHandler";
|
||||
@@ -45,11 +44,6 @@ namespace
|
||||
constexpr std::wstring_view DEFAULT_TOAST_GROUP = L"PowerToysToastTag";
|
||||
}
|
||||
|
||||
namespace localized_strings
|
||||
{
|
||||
constexpr std::wstring_view SNOOZE_BUTTON = L"Snooze";
|
||||
}
|
||||
|
||||
static DWORD loop_thread_id()
|
||||
{
|
||||
static const DWORD thread_id = GetCurrentThreadId();
|
||||
@@ -365,7 +359,7 @@ void notifications::show_toast_with_activations(std::wstring message,
|
||||
toast_xml += '"';
|
||||
}
|
||||
toast_xml += LR"( content=")";
|
||||
toast_xml += localized_strings::SNOOZE_BUTTON;
|
||||
toast_xml += b.snooze_button_title;
|
||||
toast_xml += LR"(" />)";
|
||||
} },
|
||||
actions[i]);
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace notifications
|
||||
{
|
||||
std::wstring snooze_title;
|
||||
std::vector<snooze_duration> durations;
|
||||
std::wstring snooze_button_title;
|
||||
};
|
||||
|
||||
struct link_button
|
||||
@@ -45,7 +46,7 @@ namespace notifications
|
||||
|
||||
struct progress_bar_params
|
||||
{
|
||||
std::wstring_view progress_title;
|
||||
std::wstring progress_title;
|
||||
float progress = 0.f;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,39 +9,10 @@
|
||||
#include "VersionHelper.h"
|
||||
#include "version.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
const wchar_t TOAST_TITLE[] = L"PowerToys Update";
|
||||
}
|
||||
|
||||
namespace localized_strings
|
||||
{
|
||||
const wchar_t GITHUB_NEW_VERSION_AVAILABLE[] = L"An update to PowerToys is available.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_DOWNLOAD_STARTED[] = L"PowerToys download started.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_READY_TO_INSTALL[] = L"An update to PowerToys is ready to install.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR[] = L"Error: couldn't download PowerToys installer. Visit our GitHub page to update.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_NOW[] = L"Update now";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_AFTER_RESTART[] = L"At next launch";
|
||||
|
||||
const wchar_t UNINSTALLATION_UNKNOWN_ERROR[] = L"Error: please uninstall the previous version of PowerToys manually.";
|
||||
|
||||
const wchar_t GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT[] = L"An update to PowerToys is available. Visit our GitHub page to update.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_UNAVAILABLE[] = L"PowerToys is up to date.\n";
|
||||
const wchar_t GITHUB_NEW_VERSION_VISIT[] = L"Visit";
|
||||
const wchar_t GITHUB_NEW_VERSION_MORE_INFO[] = L"More info...";
|
||||
const wchar_t GITHUB_NEW_VERSION_ABORT[] = L"Abort";
|
||||
const wchar_t GITHUB_NEW_VERSION_SNOOZE_TITLE[] = L"Click Snooze to be reminded in:";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_SNOOZE_1D[] = L"1 day";
|
||||
const wchar_t GITHUB_NEW_VERSION_UPDATE_SNOOZE_5D[] = L"5 days";
|
||||
const wchar_t DOWNLOAD_IN_PROGRESS[] = L"Downloading...";
|
||||
const wchar_t DOWNLOAD_COMPLETE[] = L"Download complete";
|
||||
}
|
||||
|
||||
namespace updating
|
||||
{
|
||||
namespace notifications
|
||||
{
|
||||
using namespace localized_strings;
|
||||
using namespace ::notifications;
|
||||
std::wstring current_version_to_next_version(const updating::new_version_download_info& info)
|
||||
{
|
||||
@@ -51,108 +22,123 @@ namespace updating
|
||||
return current_version_to_next_version;
|
||||
}
|
||||
|
||||
void show_unavailable()
|
||||
void show_unavailable(const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_UNAVAILABLE;
|
||||
show_toast(std::move(contents), TOAST_TITLE, std::move(toast_params));
|
||||
std::wstring contents = strings.GITHUB_NEW_VERSION_UNAVAILABLE;
|
||||
show_toast(std::move(contents), strings.TOAST_TITLE, std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_available(const updating::new_version_download_info& info)
|
||||
void show_available(const updating::new_version_download_info& info, const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_AVAILABLE;
|
||||
std::wstring contents = strings.GITHUB_NEW_VERSION_AVAILABLE;
|
||||
contents += L'\n';
|
||||
contents += current_version_to_next_version(info);
|
||||
|
||||
show_toast_with_activations(std::move(contents),
|
||||
TOAST_TITLE,
|
||||
strings.TOAST_TITLE,
|
||||
{},
|
||||
{ link_button{ GITHUB_NEW_VERSION_UPDATE_NOW, L"powertoys://download_and_install_update/" }, link_button{ GITHUB_NEW_VERSION_MORE_INFO, info.release_page_uri.ToString().c_str() } },
|
||||
{ link_button{ strings.GITHUB_NEW_VERSION_UPDATE_NOW,
|
||||
L"powertoys://download_and_install_update/" },
|
||||
link_button{ strings.GITHUB_NEW_VERSION_MORE_INFO,
|
||||
info.release_page_uri.ToString().c_str() } },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_download_start(const updating::new_version_download_info& info)
|
||||
void show_download_start(const updating::new_version_download_info& info, const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
progress_bar_params progress_bar_params;
|
||||
std::wstring progress_title{ info.version_string };
|
||||
progress_title += L' ';
|
||||
progress_title += localized_strings::DOWNLOAD_IN_PROGRESS;
|
||||
progress_title += strings.DOWNLOAD_IN_PROGRESS;
|
||||
|
||||
progress_bar_params.progress_title = progress_title;
|
||||
progress_bar_params.progress = .0f;
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false, std::move(progress_bar_params) };
|
||||
show_toast_with_activations(localized_strings::GITHUB_NEW_VERSION_DOWNLOAD_STARTED,
|
||||
TOAST_TITLE,
|
||||
show_toast_with_activations(strings.GITHUB_NEW_VERSION_DOWNLOAD_STARTED,
|
||||
strings.TOAST_TITLE,
|
||||
{},
|
||||
{},
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_visit_github(const updating::new_version_download_info& info)
|
||||
void show_visit_github(const updating::new_version_download_info& info, const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT;
|
||||
std::wstring contents = strings.GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT;
|
||||
contents += L'\n';
|
||||
contents += current_version_to_next_version(info);
|
||||
show_toast_with_activations(std::move(contents),
|
||||
TOAST_TITLE,
|
||||
strings.TOAST_TITLE,
|
||||
{},
|
||||
{ link_button{ GITHUB_NEW_VERSION_VISIT, info.release_page_uri.ToString().c_str() } },
|
||||
{ link_button{ strings.GITHUB_NEW_VERSION_VISIT,
|
||||
info.release_page_uri.ToString().c_str() } },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_install_error(const updating::new_version_download_info& info)
|
||||
void show_install_error(const updating::new_version_download_info& info, const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring contents = GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR;
|
||||
std::wstring contents = strings.GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR;
|
||||
contents += L'\n';
|
||||
contents += current_version_to_next_version(info);
|
||||
show_toast_with_activations(std::move(contents),
|
||||
TOAST_TITLE,
|
||||
strings.TOAST_TITLE,
|
||||
{},
|
||||
{ link_button{ GITHUB_NEW_VERSION_VISIT, info.release_page_uri.ToString().c_str() } },
|
||||
{ link_button{ strings.GITHUB_NEW_VERSION_VISIT, info.release_page_uri.ToString().c_str() } },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_version_ready(const updating::new_version_download_info& info)
|
||||
void show_version_ready(const updating::new_version_download_info& info, const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
toast_params toast_params{ UPDATING_PROCESS_TOAST_TAG, false };
|
||||
std::wstring new_version_ready{ GITHUB_NEW_VERSION_READY_TO_INSTALL };
|
||||
std::wstring new_version_ready{ strings.GITHUB_NEW_VERSION_READY_TO_INSTALL };
|
||||
new_version_ready += L'\n';
|
||||
new_version_ready += current_version_to_next_version(info);
|
||||
|
||||
show_toast_with_activations(std::move(new_version_ready),
|
||||
TOAST_TITLE,
|
||||
strings.TOAST_TITLE,
|
||||
{},
|
||||
{ link_button{ GITHUB_NEW_VERSION_UPDATE_NOW, L"powertoys://update_now/" + info.installer_filename },
|
||||
link_button{ GITHUB_NEW_VERSION_UPDATE_AFTER_RESTART, L"powertoys://schedule_update/" + info.installer_filename },
|
||||
snooze_button{ GITHUB_NEW_VERSION_SNOOZE_TITLE, { { GITHUB_NEW_VERSION_UPDATE_SNOOZE_1D, 24 * 60 }, { GITHUB_NEW_VERSION_UPDATE_SNOOZE_5D, 120 * 60 } } } },
|
||||
{ link_button{ strings.GITHUB_NEW_VERSION_UPDATE_NOW,
|
||||
L"powertoys://update_now/" + info.installer_filename },
|
||||
link_button{ strings.GITHUB_NEW_VERSION_UPDATE_AFTER_RESTART,
|
||||
L"powertoys://schedule_update/" + info.installer_filename },
|
||||
snooze_button{
|
||||
strings.GITHUB_NEW_VERSION_SNOOZE_TITLE,
|
||||
{ { strings.GITHUB_NEW_VERSION_UPDATE_SNOOZE_1D, 24 * 60 },
|
||||
{ strings.GITHUB_NEW_VERSION_UPDATE_SNOOZE_5D, 120 * 60 } },
|
||||
strings.SNOOZE_BUTTON
|
||||
} },
|
||||
std::move(toast_params));
|
||||
}
|
||||
|
||||
void show_uninstallation_error()
|
||||
void show_uninstallation_error(const notifications::strings& strings)
|
||||
{
|
||||
remove_toasts(UPDATING_PROCESS_TOAST_TAG);
|
||||
|
||||
show_toast(localized_strings::UNINSTALLATION_UNKNOWN_ERROR, TOAST_TITLE);
|
||||
show_toast(strings.UNINSTALLATION_UNKNOWN_ERROR, strings.TOAST_TITLE);
|
||||
}
|
||||
|
||||
void update_download_progress(const updating::new_version_download_info& info, float progress)
|
||||
void update_download_progress(const updating::new_version_download_info& info, float progress, const notifications::strings& strings)
|
||||
{
|
||||
progress_bar_params progress_bar_params;
|
||||
|
||||
std::wstring progress_title{ info.version_string };
|
||||
progress_title += L' ';
|
||||
progress_title += progress < 1 ? localized_strings::DOWNLOAD_IN_PROGRESS : localized_strings::DOWNLOAD_COMPLETE;
|
||||
progress_title += progress < 1 ? strings.DOWNLOAD_IN_PROGRESS : strings.DOWNLOAD_COMPLETE;
|
||||
progress_bar_params.progress_title = progress_title;
|
||||
progress_bar_params.progress = progress;
|
||||
update_toast_progress_bar(UPDATING_PROCESS_TOAST_TAG, progress_bar_params);
|
||||
|
||||
@@ -6,14 +6,66 @@ namespace updating
|
||||
|
||||
namespace notifications
|
||||
{
|
||||
void show_unavailable();
|
||||
void show_available(const updating::new_version_download_info& info);
|
||||
void show_download_start(const updating::new_version_download_info& info);
|
||||
void show_visit_github(const updating::new_version_download_info& info);
|
||||
void show_install_error(const updating::new_version_download_info& info);
|
||||
void show_version_ready(const updating::new_version_download_info& info);
|
||||
void show_uninstallation_error();
|
||||
struct strings
|
||||
{
|
||||
std::wstring GITHUB_NEW_VERSION_AVAILABLE;
|
||||
std::wstring GITHUB_NEW_VERSION_DOWNLOAD_STARTED;
|
||||
std::wstring GITHUB_NEW_VERSION_READY_TO_INSTALL;
|
||||
std::wstring GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR;
|
||||
std::wstring GITHUB_NEW_VERSION_UPDATE_NOW;
|
||||
std::wstring GITHUB_NEW_VERSION_UPDATE_AFTER_RESTART;
|
||||
std::wstring UNINSTALLATION_UNKNOWN_ERROR;
|
||||
std::wstring GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT;
|
||||
std::wstring GITHUB_NEW_VERSION_UNAVAILABLE;
|
||||
std::wstring GITHUB_NEW_VERSION_VISIT;
|
||||
std::wstring GITHUB_NEW_VERSION_MORE_INFO;
|
||||
std::wstring GITHUB_NEW_VERSION_ABORT;
|
||||
std::wstring GITHUB_NEW_VERSION_SNOOZE_TITLE;
|
||||
std::wstring SNOOZE_BUTTON;
|
||||
std::wstring GITHUB_NEW_VERSION_UPDATE_SNOOZE_1D;
|
||||
std::wstring GITHUB_NEW_VERSION_UPDATE_SNOOZE_5D;
|
||||
std::wstring DOWNLOAD_IN_PROGRESS;
|
||||
std::wstring DOWNLOAD_COMPLETE;
|
||||
std::wstring TOAST_TITLE;
|
||||
std::wstring OFFER_UNINSTALL_MSI;
|
||||
std::wstring OFFER_UNINSTALL_MSI_TITLE;
|
||||
template<typename = void>
|
||||
static strings create()
|
||||
{
|
||||
return strings{
|
||||
.GITHUB_NEW_VERSION_AVAILABLE = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_AVAILABLE),
|
||||
.GITHUB_NEW_VERSION_DOWNLOAD_STARTED = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_DOWNLOAD_STARTED),
|
||||
.GITHUB_NEW_VERSION_READY_TO_INSTALL = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_READY_TO_INSTALL),
|
||||
.GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_DOWNLOAD_INSTALL_ERROR),
|
||||
.GITHUB_NEW_VERSION_UPDATE_NOW = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_UPDATE_NOW),
|
||||
.GITHUB_NEW_VERSION_UPDATE_AFTER_RESTART = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_UPDATE_AFTER_RESTART),
|
||||
.UNINSTALLATION_UNKNOWN_ERROR = GET_RESOURCE_STRING(IDS_UNINSTALLATION_UNKNOWN_ERROR),
|
||||
.GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_AVAILABLE_OFFER_VISIT),
|
||||
.GITHUB_NEW_VERSION_UNAVAILABLE = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_UNAVAILABLE),
|
||||
.GITHUB_NEW_VERSION_VISIT = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_VISIT),
|
||||
.GITHUB_NEW_VERSION_MORE_INFO = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_MORE_INFO),
|
||||
.GITHUB_NEW_VERSION_ABORT = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_ABORT),
|
||||
.GITHUB_NEW_VERSION_SNOOZE_TITLE = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_SNOOZE_TITLE),
|
||||
.SNOOZE_BUTTON = GET_RESOURCE_STRING(IDS_SNOOZE_BUTTON),
|
||||
.GITHUB_NEW_VERSION_UPDATE_SNOOZE_1D = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_UPDATE_SNOOZE_1D),
|
||||
.GITHUB_NEW_VERSION_UPDATE_SNOOZE_5D = GET_RESOURCE_STRING(IDS_GITHUB_NEW_VERSION_UPDATE_SNOOZE_5D),
|
||||
.DOWNLOAD_IN_PROGRESS = GET_RESOURCE_STRING(IDS_DOWNLOAD_IN_PROGRESS),
|
||||
.DOWNLOAD_COMPLETE = GET_RESOURCE_STRING(IDS_DOWNLOAD_COMPLETE),
|
||||
.TOAST_TITLE = GET_RESOURCE_STRING(IDS_TOAST_TITLE),
|
||||
.OFFER_UNINSTALL_MSI = GET_RESOURCE_STRING(IDS_OFFER_UNINSTALL_MSI),
|
||||
.OFFER_UNINSTALL_MSI_TITLE = GET_RESOURCE_STRING(IDS_OFFER_UNINSTALL_MSI_TITLE)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
void update_download_progress(const updating::new_version_download_info& info, float progress);
|
||||
void show_unavailable(const notifications::strings& strings);
|
||||
void show_available(const updating::new_version_download_info& info, const strings&);
|
||||
void show_download_start(const updating::new_version_download_info& info, const strings&);
|
||||
void show_visit_github(const updating::new_version_download_info& info, const strings&);
|
||||
void show_install_error(const updating::new_version_download_info& info, const strings&);
|
||||
void show_version_ready(const updating::new_version_download_info& info, const strings&);
|
||||
void show_uninstallation_error(const notifications::strings& strings);
|
||||
|
||||
void update_download_progress(const updating::new_version_download_info& info, float progress, const notifications::strings& strings);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "VersionHelper.h"
|
||||
#include <PathCch.h>
|
||||
|
||||
namespace
|
||||
namespace // Strings in this namespace should not be localized
|
||||
{
|
||||
const wchar_t POWER_TOYS_UPGRADE_CODE[] = L"{42B84BF7-5FBF-473B-9C8B-049DC16F7708}";
|
||||
const wchar_t POWERTOYS_EXE_COMPONENT[] = L"{A2C66D91-3485-4D00-B04D-91844E6B345B}";
|
||||
@@ -32,12 +32,6 @@ namespace
|
||||
const wchar_t TOAST_TITLE[] = L"PowerToys";
|
||||
}
|
||||
|
||||
namespace localized_strings
|
||||
{
|
||||
const wchar_t OFFER_UNINSTALL_MSI[] = L"We've detected a previous installation of PowerToys. Would you like to remove it?";
|
||||
const wchar_t OFFER_UNINSTALL_MSI_TITLE[] = L"PowerToys: uninstall previous version?";
|
||||
}
|
||||
|
||||
namespace updating
|
||||
{
|
||||
std::wstring get_msi_package_path()
|
||||
@@ -73,13 +67,18 @@ namespace updating
|
||||
return package_path;
|
||||
}
|
||||
|
||||
bool offer_msi_uninstallation()
|
||||
bool offer_msi_uninstallation(const notifications::strings& strings)
|
||||
{
|
||||
const auto selection = SHMessageBoxCheckW(nullptr, localized_strings::OFFER_UNINSTALL_MSI, localized_strings::OFFER_UNINSTALL_MSI_TITLE, MB_ICONQUESTION | MB_YESNO, IDNO, DONT_SHOW_AGAIN_RECORD_REGISTRY_PATH);
|
||||
const auto selection = SHMessageBoxCheckW(nullptr,
|
||||
strings.OFFER_UNINSTALL_MSI.c_str(),
|
||||
strings.OFFER_UNINSTALL_MSI_TITLE.c_str(),
|
||||
MB_ICONQUESTION | MB_YESNO,
|
||||
IDNO,
|
||||
DONT_SHOW_AGAIN_RECORD_REGISTRY_PATH);
|
||||
return selection == IDYES;
|
||||
}
|
||||
|
||||
bool uninstall_msi_version(const std::wstring& package_path)
|
||||
bool uninstall_msi_version(const std::wstring& package_path, const notifications::strings& strings)
|
||||
{
|
||||
const auto uninstall_result = MsiInstallProductW(package_path.c_str(), L"REMOVE=ALL");
|
||||
if (ERROR_SUCCESS == uninstall_result)
|
||||
@@ -94,7 +93,7 @@ namespace updating
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
updating::notifications::show_uninstallation_error();
|
||||
updating::notifications::show_uninstallation_error(strings);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -202,7 +201,7 @@ namespace updating
|
||||
return installer_download_dst;
|
||||
}
|
||||
|
||||
std::future<void> try_autoupdate(const bool download_updates_automatically)
|
||||
std::future<void> try_autoupdate(const bool download_updates_automatically, const notifications::strings& strings)
|
||||
{
|
||||
const auto new_version = co_await get_new_github_version_info_async();
|
||||
if (!new_version)
|
||||
@@ -230,32 +229,32 @@ namespace updating
|
||||
}
|
||||
if (!download_success)
|
||||
{
|
||||
updating::notifications::show_install_error(new_version.value());
|
||||
updating::notifications::show_install_error(new_version.value(), strings);
|
||||
co_return;
|
||||
}
|
||||
|
||||
updating::notifications::show_version_ready(new_version.value());
|
||||
updating::notifications::show_version_ready(new_version.value(), strings);
|
||||
}
|
||||
else
|
||||
{
|
||||
updating::notifications::show_visit_github(new_version.value());
|
||||
updating::notifications::show_visit_github(new_version.value(), strings);
|
||||
}
|
||||
}
|
||||
|
||||
std::future<std::wstring> check_new_version_available()
|
||||
std::future<std::wstring> check_new_version_available(const notifications::strings& strings)
|
||||
{
|
||||
const auto new_version = co_await get_new_github_version_info_async();
|
||||
if (!new_version)
|
||||
{
|
||||
updating::notifications::show_unavailable();
|
||||
updating::notifications::show_unavailable(strings);
|
||||
co_return VersionHelper{ VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION }.toWstring();
|
||||
}
|
||||
|
||||
updating::notifications::show_available(new_version.value());
|
||||
updating::notifications::show_available(new_version.value(), strings);
|
||||
co_return new_version->version_string;
|
||||
}
|
||||
|
||||
std::future<std::wstring> download_update()
|
||||
std::future<std::wstring> download_update(const notifications::strings& strings)
|
||||
{
|
||||
const auto new_version = co_await get_new_github_version_info_async();
|
||||
if (!new_version)
|
||||
@@ -264,12 +263,12 @@ namespace updating
|
||||
}
|
||||
|
||||
auto installer_download_dst = create_download_path() / new_version->installer_filename;
|
||||
updating::notifications::show_download_start(new_version.value());
|
||||
updating::notifications::show_download_start(new_version.value(), strings);
|
||||
|
||||
try
|
||||
{
|
||||
auto progressUpdateHandle = [&](float progress) {
|
||||
updating::notifications::update_download_progress(new_version.value(), progress);
|
||||
updating::notifications::update_download_progress(new_version.value(), progress, strings);
|
||||
};
|
||||
|
||||
http::HttpClient client;
|
||||
@@ -277,7 +276,7 @@ namespace updating
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
updating::notifications::show_install_error(new_version.value());
|
||||
updating::notifications::show_install_error(new_version.value(), strings);
|
||||
co_return L"";
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,14 @@
|
||||
#include <filesystem>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
|
||||
#include "notifications.h"
|
||||
#include "../VersionHelper.h"
|
||||
|
||||
namespace updating
|
||||
{
|
||||
std::wstring get_msi_package_path();
|
||||
bool uninstall_msi_version(const std::wstring& package_path);
|
||||
bool offer_msi_uninstallation();
|
||||
bool uninstall_msi_version(const std::wstring& package_path, const notifications::strings&);
|
||||
bool offer_msi_uninstallation(const notifications::strings&);
|
||||
std::optional<std::wstring> get_msi_package_installed_path();
|
||||
std::optional<VersionHelper> get_installed_powertoys_version();
|
||||
|
||||
@@ -27,11 +28,11 @@ namespace updating
|
||||
};
|
||||
|
||||
std::future<std::optional<new_version_download_info>> get_new_github_version_info_async();
|
||||
std::future<void> try_autoupdate(const bool download_updates_automatically);
|
||||
std::future<void> try_autoupdate(const bool download_updates_automatically, const notifications::strings&);
|
||||
std::filesystem::path get_pending_updates_path();
|
||||
|
||||
std::future<std::wstring> check_new_version_available();
|
||||
std::future<std::wstring> download_update();
|
||||
std::future<std::wstring> check_new_version_available(const notifications::strings&);
|
||||
std::future<std::wstring> download_update(const notifications::strings&);
|
||||
|
||||
// non-localized
|
||||
constexpr inline std::wstring_view INSTALLER_FILENAME_PATTERN = L"powertoyssetup";
|
||||
|
||||
Reference in New Issue
Block a user