Skip to content

Commit

Permalink
Added auto download and install option
Browse files Browse the repository at this point in the history
  • Loading branch information
brianferguson committed Aug 25, 2021
1 parent c7ef39c commit b0f5d6b
Show file tree
Hide file tree
Showing 11 changed files with 512 additions and 144 deletions.
3 changes: 3 additions & 0 deletions Language/Resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,7 @@ STRINGTABLE
ID_STR_GAMEMODE_ACTIONS_DESC, STR_GAMEMODE_ACTIONS_DESC
ID_STR_GAMEMODE_ACTIONS_UNLOADALL, STR_GAMEMODE_ACTIONS_UNLOADALL
ID_STR_GAMEMODE_ACTIONS_CURRENT, STR_GAMEMODE_ACTIONS_CURRENT
ID_STR_AUTOMATICUPDATE, "Automatically install updates"
ID_STR_INSTALL_NEW_VERSION, "Install new version"
ID_STR_CLICK_TO_INSTALL, "Restart Rainmeter to install version: %1"
}
25 changes: 19 additions & 6 deletions Library/ContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,32 @@ void ContextMenu::ShowMenu(POINT pos, Skin* skin)
++index;
}

bool newVersion = rainmeter.GetNewVersion();
bool downloadedNewVersion = rainmeter.GetDownloadedNewVersion();
bool obsoleteLanguage = rainmeter.GetLanguageStatus();
int sepPos = 0;

// Add update notification item
if (rainmeter.GetNewVersion())
if (newVersion || downloadedNewVersion)
{
InsertMenu(menu, 0, MF_BYPOSITION, IDM_NEW_VERSION, GetString(ID_STR_UPDATEAVAILABLE));
UINT_PTR idm = downloadedNewVersion ? IDM_INSTALL_NEW_VERSION : IDM_NEW_VERSION;
WCHAR * str = GetString(downloadedNewVersion ? ID_STR_INSTALL_NEW_VERSION : ID_STR_UPDATEAVAILABLE);
InsertMenu(menu, 0, MF_BYPOSITION, idm, str);
HiliteMenuItem(rainmeter.GetTrayIcon()->GetWindow(), menu, 0, MF_BYPOSITION | MF_HILITE);
InsertMenu(menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, nullptr);
++sepPos;
}

// Add language status if obsolete
if (rainmeter.GetLanguageStatus())
if (obsoleteLanguage)
{
InsertMenu(menu, !newVersion ? 0 : 1, MF_BYPOSITION, IDM_LANGUAGEOBSOLETE, GetString(ID_STR_LANGUAGEOBSOLETE));
++sepPos;
}

// Add separator if necessary
if (sepPos > 0)
{
InsertMenu(menu, !rainmeter.m_NewVersion ? 0 : 1, MF_BYPOSITION, IDM_LANGUAGEOBSOLETE, GetString(ID_STR_LANGUAGEOBSOLETE));
if (!rainmeter.GetNewVersion()) InsertMenu(menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, nullptr);
InsertMenu(menu, sepPos, MF_BYPOSITION | MF_SEPARATOR, 0, nullptr);
}
}

Expand Down
51 changes: 32 additions & 19 deletions Library/DialogManage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@ void DialogManage::TabSettings::Create(HWND owner)
const ControlTemplate::Control s_Controls[] =
{
CT_GROUPBOX(-0, ID_STR_GENERAL,
0, 0, 478, 131,
0, 0, 478, 144,
WS_VISIBLE, 0),
CT_LABEL(-0, ID_STR_LANGUAGESC,
6, 15, 107, 14,
Expand All @@ -2344,33 +2344,36 @@ void DialogManage::TabSettings::Create(HWND owner)
CT_CHECKBOX(Id_CheckForUpdatesCheckBox, ID_STR_CHECKFORUPDATES,
6, 55, 200, 9,
WS_VISIBLE | WS_TABSTOP, 0),
CT_CHECKBOX(Id_LockSkinsCheckBox, ID_STR_DISABLEDRAGGING,
CT_CHECKBOX(Id_AutoInstallCheckBox, ID_STR_AUTOMATICUPDATE,
6, 68, 200, 9,
WS_VISIBLE | WS_TABSTOP, 0),
CT_CHECKBOX(Id_ShowTrayIconCheckBox, ID_STR_SHOWNOTIFICATIONAREAICON,
CT_CHECKBOX(Id_LockSkinsCheckBox, ID_STR_DISABLEDRAGGING,
6, 81, 200, 9,
WS_VISIBLE | WS_TABSTOP, 0),
CT_CHECKBOX(Id_UseHardwareAccelerationCheckBox, ID_STR_HARDWAREACCELERATED,
CT_CHECKBOX(Id_ShowTrayIconCheckBox, ID_STR_SHOWNOTIFICATIONAREAICON,
6, 94, 200, 9,
WS_VISIBLE | WS_TABSTOP, 0),
CT_CHECKBOX(Id_UseHardwareAccelerationCheckBox, ID_STR_HARDWAREACCELERATED,
6, 107, 200, 9,
WS_VISIBLE | WS_TABSTOP, 0),
CT_BUTTON(Id_ResetStatisticsButton, ID_STR_RESETSTATISTICS,
6, 110, buttonWidth + 20, 14,
6, 123, buttonWidth + 20, 14,
WS_VISIBLE | WS_TABSTOP, 0),

CT_GROUPBOX(-0, ID_STR_LOGGING,
0, 138, 478, 66,
0, 151, 478, 66,
WS_VISIBLE, 0),
CT_CHECKBOX(Id_VerboseLoggingCheckbox, ID_STR_DEBUGMODE,
6, 154, 200, 9,
CT_CHECKBOX(Id_VerboseLoggingCheckBox, ID_STR_DEBUGMODE,
6, 167, 200, 9,
WS_VISIBLE | WS_TABSTOP, 0),
CT_CHECKBOX(Id_LogToFileCheckBox, ID_STR_LOGTOFILE,
6, 167, 200, 9,
6, 180, 200, 9,
WS_VISIBLE | WS_TABSTOP, 0),
CT_BUTTON(Id_ShowLogFileButton, ID_STR_SHOWLOGFILE,
6, 183, buttonWidth + 20, 14,
6, 196, buttonWidth + 20, 14,
WS_VISIBLE | WS_TABSTOP, 0),
CT_BUTTON(Id_DeleteLogFileButton, ID_STR_DELETELOGFILE,
buttonWidth + 30, 183, buttonWidth + 20, 14,
buttonWidth + 30, 196, buttonWidth + 20, 14,
WS_VISIBLE | WS_TABSTOP, 0)
};

Expand Down Expand Up @@ -2423,10 +2426,14 @@ void DialogManage::TabSettings::Initialize()
FindClose(hSearch);
}

Button_SetCheck(GetControl(Id_CheckForUpdatesCheckBox), !GetRainmeter().GetDisableVersionCheck());
BOOL check = !GetRainmeter().GetDisableVersionCheck();
Button_SetCheck(GetControl(Id_CheckForUpdatesCheckBox), check);
Button_SetCheck(GetControl(Id_AutoInstallCheckBox), !GetRainmeter().GetDisableAutoUpdate());
EnableWindow(GetControl(Id_AutoInstallCheckBox), check);

Button_SetCheck(GetControl(Id_LockSkinsCheckBox), GetRainmeter().GetDisableDragging());
Button_SetCheck(GetControl(Id_LogToFileCheckBox), GetLogger().IsLogToFile());
Button_SetCheck(GetControl(Id_VerboseLoggingCheckbox), GetRainmeter().GetDebug());
Button_SetCheck(GetControl(Id_VerboseLoggingCheckBox), GetRainmeter().GetDebug());

BOOL isLogFile = (_waccess(GetLogger().GetLogFilePath().c_str(), 0) != -1);
EnableWindow(GetControl(Id_ShowLogFileButton), isLogFile);
Expand Down Expand Up @@ -2522,7 +2529,7 @@ INT_PTR DialogManage::TabSettings::OnCommand(WPARAM wParam, LPARAM lParam)
}
}

GetUpdater().CheckLanguage();
GetUpdater().GetLanguageStatus();

SendMessage(c_Dialog->GetWindow(), WM_CLOSE, 0, 0);
GetRainmeter().DelayedExecuteCommand(L"!Manage Settings");
Expand All @@ -2531,7 +2538,15 @@ INT_PTR DialogManage::TabSettings::OnCommand(WPARAM wParam, LPARAM lParam)
break;

case Id_CheckForUpdatesCheckBox:
GetRainmeter().SetDisableVersionCheck(!GetRainmeter().GetDisableVersionCheck());
{
BOOL check = GetRainmeter().GetDisableVersionCheck();
GetRainmeter().SetDisableVersionCheck(!check);
EnableWindow(GetControl(Id_AutoInstallCheckBox), check);
}
break;

case Id_AutoInstallCheckBox:
GetRainmeter().SetDisableAutoUpdate(!GetRainmeter().GetDisableAutoUpdate());
break;

case Id_LockSkinsCheckBox:
Expand Down Expand Up @@ -2572,7 +2587,7 @@ INT_PTR DialogManage::TabSettings::OnCommand(WPARAM wParam, LPARAM lParam)
}
break;

case Id_VerboseLoggingCheckbox:
case Id_VerboseLoggingCheckBox:
GetRainmeter().SetDebug(!GetRainmeter().GetDebug());
break;

Expand Down Expand Up @@ -2640,9 +2655,7 @@ INT_PTR DialogManage::TabSettings::OnCommand(WPARAM wParam, LPARAM lParam)
MB_ICONQUESTION | MB_OKCANCEL | MB_DEFBUTTON1 | MB_TOPMOST);
if (result == IDOK)
{
std::wstring restart = GetRainmeter().GetPath();
restart += L"RestartRainmeter.exe";
CommandHandler::RunFile(restart.c_str());
GetRainmeter().RestartRainmeter();
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion Library/DialogManage.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,11 @@ class DialogManage : public Dialog
enum Id
{
Id_CheckForUpdatesCheckBox = 100,
Id_AutoInstallCheckBox,
Id_LockSkinsCheckBox,
Id_ResetStatisticsButton,
Id_LogToFileCheckBox,
Id_VerboseLoggingCheckbox,
Id_VerboseLoggingCheckBox,
Id_ShowLogFileButton,
Id_DeleteLogFileButton,
Id_LanguageDropDownList,
Expand Down
4 changes: 2 additions & 2 deletions Library/Library.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
<Link>
<AdditionalDependencies>comctl32.lib;dwmapi.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;d3d11.lib;d2d1.lib;dwrite.lib;windowscodecs.lib;Version.lib;Imagehlp.lib;Urlmon.lib;psapi.lib;dxguid.lib;Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>dwmapi.dll;Iphlpapi.dll;Winmm.dll;Version.dll;Imagehlp.dll;Urlmon.dll;psapi.dll;$(DelayLoadTestDLL)</DelayLoadDLLs>
<AdditionalDependencies>Bcrypt.lib;comctl32.lib;dwmapi.lib;Wininet.lib;UxTheme.lib;Winmm.lib;gdiplus.lib;Iphlpapi.lib;shlwapi.lib;d3d11.lib;d2d1.lib;dwrite.lib;windowscodecs.lib;Version.lib;Imagehlp.lib;Urlmon.lib;psapi.lib;dxguid.lib;Rpcrt4.lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>Bcrypt.dll;dwmapi.dll;Iphlpapi.dll;Winmm.dll;Version.dll;Imagehlp.dll;Urlmon.dll;psapi.dll;$(DelayLoadTestDLL)</DelayLoadDLLs>
<ModuleDefinitionFile>Exports.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
Expand Down
64 changes: 63 additions & 1 deletion Library/Rainmeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Rainmeter::Rainmeter() :
m_Debug(false),
m_DisableVersionCheck(false),
m_NewVersion(false),
m_DisableAutoUpdate(false),
m_DownloadedNewVersion(false),
m_LanguageObsolete(false),
m_DesktopWorkAreaChanged(false),
m_DesktopWorkAreaType(false),
Expand Down Expand Up @@ -309,6 +311,50 @@ int Rainmeter::Initialize(LPCWSTR iniPath, LPCWSTR layout, bool safeStart)
CreateDataFile();
}

// Install new version
if (GetPrivateProfileString(L"Rainmeter", L"InstallerName", L"", buffer, MAX_LINE_LENGTH, m_DataFile.c_str()) != 0)
{
bool runInstaller = false;
const std::wstring installerName = buffer;
const std::wstring updatePath = m_SettingsPath + L"Updates\\";
const std::wstring fullPath = updatePath + installerName;
if (PathFileExists(fullPath.c_str()))
{
if (GetPrivateProfileString(L"Rainmeter", L"InstallerSha256", L"", buffer, MAX_LINE_LENGTH, m_DataFile.c_str()) != 0)
{
const std::wstring sha256 = buffer;
runInstaller = Updater::VerifyInstaller(updatePath, installerName, sha256, false);
WritePrivateProfileString(L"Rainmeter", L"InstallerSha256", nullptr, m_DataFile.c_str());
}
}

WritePrivateProfileString(L"Rainmeter", L"InstallerName", nullptr, m_DataFile.c_str());
WritePrivateProfileString(L"Rainmeter", L"DeleteInstaller", installerName.c_str(), m_DataFile.c_str());

if (runInstaller)
{
const std::wstring isPortable = _wcsicmp(m_Path.c_str(), m_SettingsPath.c_str()) == 0 ? L"1" : L"0";
const std::wstring is64Bit = APPBITS == L"64-bit" ? L"1" : L"0";
const std::wstring args = L"/S /RESTART=1 /PORTABLE=" + isPortable + L" /VERSION" + is64Bit + L" /D=" + m_Path.c_str();
CommandHandler::RunFile(fullPath.c_str(), args.c_str());
clearBuffer();
return -1;
}
}

// Delete installer if necessary
if (GetPrivateProfileString(L"Rainmeter", L"DeleteInstaller", L"", buffer, MAX_LINE_LENGTH, m_DataFile.c_str()) != 0)
{
const std::wstring updatePath = m_SettingsPath + L"Updates\\";
const std::wstring fullPath = updatePath + buffer;
if (PathFileExists(fullPath.c_str()))
{
System::RemoveFile(fullPath);
}
WritePrivateProfileString(L"Rainmeter", L"DeleteInstaller", nullptr, m_DataFile.c_str());
RemoveDirectory(updatePath.c_str());
}

// Reset log file
System::RemoveFile(logger.GetLogFilePath());

Expand Down Expand Up @@ -506,7 +552,7 @@ int Rainmeter::Initialize(LPCWSTR iniPath, LPCWSTR layout, bool safeStart)
}
else if (!m_DisableVersionCheck)
{
GetUpdater().CheckUpdate();
GetUpdater().CheckForUpdates(!m_DisableAutoUpdate);
}

return 0; // All is OK
Expand Down Expand Up @@ -564,6 +610,14 @@ void Rainmeter::Finalize()
UnregisterClass(RAINMETER_CLASS_NAME, m_Instance);
}

void Rainmeter::RestartRainmeter()
{
// Make sure to call after m_Path is initialized in Rainmeter::Initialize
std::wstring restart = m_Path;
restart += L"RestartRainmeter.exe";
CommandHandler::RunFile(restart.c_str());
}

bool Rainmeter::IsAlreadyRunning()
{
typedef struct
Expand Down Expand Up @@ -1514,6 +1568,7 @@ void Rainmeter::ReadGeneralSettings(const std::wstring& iniFile)
m_TrayExecuteDM = parser.ReadString(L"Rainmeter", L"TrayExecuteDM", L"", false);

m_DisableVersionCheck = parser.ReadBool(L"Rainmeter", L"DisableVersionCheck", false);
m_DisableAutoUpdate = parser.ReadBool(L"Rainmeter", L"DisableAutoUpdate", false);

const std::wstring& area = parser.ReadString(L"Rainmeter", L"DesktopWorkArea", L"");
if (!area.empty())
Expand Down Expand Up @@ -1706,6 +1761,7 @@ bool Rainmeter::LoadLayout(const std::wstring& name)
PreserveSetting(backup, L"ConfigEditor");
PreserveSetting(backup, L"Logging");
PreserveSetting(backup, L"DisableVersionCheck");
PreserveSetting(backup, L"DisableAutoUpdate");
PreserveSetting(backup, L"Language");
PreserveSetting(backup, L"NormalStayDesktop");
PreserveSetting(backup, L"SelectedColor");
Expand Down Expand Up @@ -2017,6 +2073,12 @@ void Rainmeter::SetDisableVersionCheck(bool check)
WritePrivateProfileString(L"Rainmeter", L"DisableVersionCheck", check ? L"1" : L"0" , m_IniFile.c_str());
}

void Rainmeter::SetDisableAutoUpdate(bool check)
{
m_DisableAutoUpdate = check;
WritePrivateProfileString(L"Rainmeter", L"DisableAutoUpdate", check ? L"1" : L"0", m_IniFile.c_str());
}

void Rainmeter::TestSettingsFile(bool bDefaultIniLocation)
{
const WCHAR* iniFile = m_IniFile.c_str();
Expand Down
8 changes: 8 additions & 0 deletions Library/Rainmeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Rainmeter
int Initialize(LPCWSTR iniPath, LPCWSTR layout, bool safeStart);
void Finalize();

void RestartRainmeter();

bool IsAlreadyRunning();
int MessagePump();

Expand Down Expand Up @@ -138,6 +140,10 @@ class Rainmeter
void SetDisableVersionCheck(bool check);
bool GetNewVersion() { return m_NewVersion; }
void SetNewVersion() { m_NewVersion = true; }
bool GetDisableAutoUpdate() { return m_DisableAutoUpdate; }
void SetDisableAutoUpdate(bool check);
bool GetDownloadedNewVersion() { return m_DownloadedNewVersion; }
void SetDownloadedNewVersion() { m_DownloadedNewVersion = true; }
bool GetLanguageStatus() { return m_LanguageObsolete; }
void SetLanguageStatus(bool status) { m_LanguageObsolete = status; DialogManage::UpdateLanguageStatus(); }

Expand Down Expand Up @@ -245,6 +251,8 @@ class Rainmeter

bool m_DisableVersionCheck;
bool m_NewVersion;
bool m_DisableAutoUpdate;
bool m_DownloadedNewVersion;
bool m_LanguageObsolete;

bool m_HardwareAccelerated;
Expand Down
16 changes: 15 additions & 1 deletion Library/TrayIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,18 @@ void TrayIcon::ShowWelcomeNotification()
ShowNotification(TRAY_NOTIFICATION_WELCOME, GetString(ID_STR_WELCOME), GetString(ID_STR_CLICKTOMANAGE));
}

void TrayIcon::ShowUpdateNotification(const WCHAR* newVersion)
void TrayIcon::ShowUpdateNotification(LPCWSTR newVersion)
{
std::wstring text = GetFormattedString(ID_STR_CLICKTODOWNLOAD, newVersion);
ShowNotification(TRAY_NOTIFICATION_UPDATE, GetString(ID_STR_UPDATEAVAILABLE), text.c_str());
}

void TrayIcon::ShowInstallUpdateNotification(LPCWSTR newVersion)
{
std::wstring text = GetFormattedString(ID_STR_CLICK_TO_INSTALL, newVersion);
ShowNotification(TRAY_NOTIFICATION_INSTALL_UPDATE, GetString(ID_STR_INSTALL_NEW_VERSION), text.c_str());
}

void TrayIcon::SetTrayIcon(bool enabled, bool setTemporarily)
{
enabled ? TryAddTrayIcon() : RemoveTrayIcon();
Expand Down Expand Up @@ -524,6 +530,10 @@ LRESULT CALLBACK TrayIcon::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
CommandHandler::RunFile(RAINMETER_OFFICIAL);
break;

case IDM_INSTALL_NEW_VERSION:
GetRainmeter().RestartRainmeter();
break;

case IDM_LANGUAGEOBSOLETE:
CommandHandler::RunFile(RAINMETER_LOCALIZATION);
break;
Expand Down Expand Up @@ -704,6 +714,10 @@ LRESULT CALLBACK TrayIcon::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
{
CommandHandler::RunFile(RAINMETER_OFFICIAL);
}
else if (tray->m_Notification == TRAY_NOTIFICATION_INSTALL_UPDATE)
{
GetRainmeter().RestartRainmeter();
}
tray->m_Notification = TRAY_NOTIFICATION_NONE;
break;

Expand Down
6 changes: 4 additions & 2 deletions Library/TrayIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class TrayIcon
void SetTrayIcon(bool enabled, bool setTemporarily = false);

void ShowWelcomeNotification();
void ShowUpdateNotification(const WCHAR* newVersion);
void ShowUpdateNotification(LPCWSTR newVersion);
void ShowInstallUpdateNotification(LPCWSTR newVersion);

protected:
static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Expand All @@ -53,7 +54,8 @@ class TrayIcon
{
TRAY_NOTIFICATION_NONE,
TRAY_NOTIFICATION_WELCOME,
TRAY_NOTIFICATION_UPDATE
TRAY_NOTIFICATION_UPDATE,
TRAY_NOTIFICATION_INSTALL_UPDATE
};

bool AddTrayIcon();
Expand Down
Loading

0 comments on commit b0f5d6b

Please sign in to comment.