mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
Now updater is comparing versions instead of comparing thier strings
This commit is contained in:
committed by
Andrey Nekrasov
parent
0016836022
commit
f015995ac4
@@ -1,6 +1,8 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include <settings_objects.h>
|
#include <settings_objects.h>
|
||||||
|
|
||||||
|
#include "VersionHelper.h"
|
||||||
|
|
||||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
using namespace PowerToysSettings;
|
using namespace PowerToysSettings;
|
||||||
|
|
||||||
|
|||||||
@@ -95,6 +95,7 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="UnitTestsVersionHelper.cpp" />
|
||||||
<ClCompile Include="pch.cpp">
|
<ClCompile Include="pch.cpp">
|
||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
<ClCompile Include="Settings.Tests.cpp">
|
<ClCompile Include="Settings.Tests.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="UnitTestsVersionHelper.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="pch.h">
|
<ClInclude Include="pch.h">
|
||||||
|
|||||||
97
src/common/UnitTests-CommonLib/UnitTestsVersionHelper.cpp
Normal file
97
src/common/UnitTests-CommonLib/UnitTestsVersionHelper.cpp
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
#include "pch.h"
|
||||||
|
|
||||||
|
#include "VersionHelper.h"
|
||||||
|
|
||||||
|
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||||
|
|
||||||
|
namespace UnitTestsVersionHelper
|
||||||
|
{
|
||||||
|
const int MAJOR_VERSION_0 = 0;
|
||||||
|
const int MINOR_VERSION_12 = 12;
|
||||||
|
const int REVISION_VERSION_0 = 0;
|
||||||
|
|
||||||
|
TEST_CLASS(UnitTestsVersionHelper)
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
TEST_METHOD(integerConstructorShouldProprelyInitializateVersionNumbers)
|
||||||
|
{
|
||||||
|
VersionHelper sut(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||||
|
|
||||||
|
Assert::AreEqual(MAJOR_VERSION_0, sut.major);
|
||||||
|
Assert::AreEqual(MINOR_VERSION_12, sut.minor);
|
||||||
|
Assert::AreEqual(REVISION_VERSION_0, sut.revision);
|
||||||
|
}
|
||||||
|
TEST_METHOD(integerConstructorShouldProprelyInitializateWithDifferentVersionNumbers)
|
||||||
|
{
|
||||||
|
const int testcaseMajor = 2;
|
||||||
|
const int testcaseMinor = 25;
|
||||||
|
const int testcaseRevision = 1;
|
||||||
|
VersionHelper sut(testcaseMajor, testcaseMinor, testcaseRevision);
|
||||||
|
|
||||||
|
Assert::AreEqual(testcaseMajor, sut.major);
|
||||||
|
Assert::AreEqual(testcaseMinor, sut.minor);
|
||||||
|
Assert::AreEqual(testcaseRevision, sut.revision);
|
||||||
|
}
|
||||||
|
TEST_METHOD(stringConstructorShouldProprelyInitializateVersionNumbers)
|
||||||
|
{
|
||||||
|
|
||||||
|
VersionHelper sut("v0.12.3");
|
||||||
|
|
||||||
|
Assert::AreEqual(0, sut.major);
|
||||||
|
Assert::AreEqual(12, sut.minor);
|
||||||
|
Assert::AreEqual(3, sut.revision);
|
||||||
|
}
|
||||||
|
TEST_METHOD(stringConstructorShouldProprelyInitializateWithDifferentVersionNumbers)
|
||||||
|
{
|
||||||
|
VersionHelper sut("v2.25.1");
|
||||||
|
|
||||||
|
Assert::AreEqual(2, sut.major);
|
||||||
|
Assert::AreEqual(25, sut.minor);
|
||||||
|
Assert::AreEqual(1, sut.revision);
|
||||||
|
}
|
||||||
|
TEST_METHOD(whenMajorVersionIsGreaterComparationOperatorShouldReturnProperValue)
|
||||||
|
{
|
||||||
|
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||||
|
VersionHelper lhs(MAJOR_VERSION_0 + 1, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||||
|
|
||||||
|
Assert::IsTrue(lhs > rhs);
|
||||||
|
}
|
||||||
|
TEST_METHOD(whenMajorVersionIsLesserComparationOperatorShouldReturnProperValue)
|
||||||
|
{
|
||||||
|
VersionHelper rhs(MAJOR_VERSION_0 + 1, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||||
|
VersionHelper lhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||||
|
|
||||||
|
Assert::IsFalse(lhs > rhs);
|
||||||
|
}
|
||||||
|
TEST_METHOD(whenMajorVersionIsEqualComparationOperatorShouldCompareMinorVersionValue)
|
||||||
|
{
|
||||||
|
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12 - 1, REVISION_VERSION_0);
|
||||||
|
|
||||||
|
VersionHelper lhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||||
|
|
||||||
|
Assert::IsTrue(lhs > rhs);
|
||||||
|
}
|
||||||
|
TEST_METHOD(whenMajorVersionIsEqualComparationOperatorShouldCompareMinorVersionValue2)
|
||||||
|
{
|
||||||
|
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||||
|
VersionHelper lhs(MAJOR_VERSION_0, MINOR_VERSION_12 - 1, REVISION_VERSION_0);
|
||||||
|
|
||||||
|
Assert::IsFalse(lhs > rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_METHOD(whenMajorAndMinorVersionIsEqualComparationOperatorShouldCompareRevisionValue)
|
||||||
|
{
|
||||||
|
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||||
|
VersionHelper lhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0 + 1);
|
||||||
|
|
||||||
|
Assert::IsTrue(lhs > rhs);
|
||||||
|
}
|
||||||
|
TEST_METHOD(whenMajorAndMinorVersionIsEqualComparationOperatorShouldCompareRevisionValue2)
|
||||||
|
{
|
||||||
|
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0 + 1);
|
||||||
|
VersionHelper lhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||||
|
|
||||||
|
Assert::IsFalse(lhs > rhs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
63
src/common/VersionHelper.cpp
Normal file
63
src/common/VersionHelper.cpp
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
#include "pch.h"
|
||||||
|
#include "VersionHelper.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
VersionHelper::VersionHelper(std::string str)
|
||||||
|
{
|
||||||
|
std::replace(str.begin(), str.end(), '.', ' ');
|
||||||
|
std::replace(str.begin(), str.end(), 'v', ' ');
|
||||||
|
std::stringstream ss;
|
||||||
|
|
||||||
|
ss << str;
|
||||||
|
|
||||||
|
std::string temp;
|
||||||
|
ss >> temp;
|
||||||
|
std::stringstream(temp) >> major;
|
||||||
|
ss >> temp;
|
||||||
|
std::stringstream(temp) >> minor;
|
||||||
|
ss >> temp;
|
||||||
|
std::stringstream(temp) >> revision;
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionHelper::VersionHelper(int major, int minor, int revision) :
|
||||||
|
major(major),
|
||||||
|
minor(minor),
|
||||||
|
revision(revision)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VersionHelper::operator>(const VersionHelper& rhs)
|
||||||
|
{
|
||||||
|
if (major < rhs.major)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (major > rhs.major)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (minor < rhs.minor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (minor > rhs.minor)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (revision < rhs.revision)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
15
src/common/VersionHelper.h
Normal file
15
src/common/VersionHelper.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct VersionHelper
|
||||||
|
{
|
||||||
|
VersionHelper(std::string str);
|
||||||
|
VersionHelper(int major, int minor, int revision);
|
||||||
|
|
||||||
|
bool operator>(const VersionHelper& rhs);
|
||||||
|
|
||||||
|
int major;
|
||||||
|
int minor;
|
||||||
|
int revision;
|
||||||
|
};
|
||||||
@@ -108,6 +108,7 @@
|
|||||||
<ClInclude Include="com_object_factory.h" />
|
<ClInclude Include="com_object_factory.h" />
|
||||||
<ClInclude Include="notifications.h" />
|
<ClInclude Include="notifications.h" />
|
||||||
<ClInclude Include="timeutil.h" />
|
<ClInclude Include="timeutil.h" />
|
||||||
|
<ClInclude Include="VersionHelper.h" />
|
||||||
<ClInclude Include="window_helpers.h" />
|
<ClInclude Include="window_helpers.h" />
|
||||||
<ClInclude Include="icon_helpers.h" />
|
<ClInclude Include="icon_helpers.h" />
|
||||||
<ClInclude Include="json.h" />
|
<ClInclude Include="json.h" />
|
||||||
@@ -146,6 +147,7 @@
|
|||||||
<ClCompile Include="start_visible.cpp" />
|
<ClCompile Include="start_visible.cpp" />
|
||||||
<ClCompile Include="tasklist_positions.cpp" />
|
<ClCompile Include="tasklist_positions.cpp" />
|
||||||
<ClCompile Include="common.cpp" />
|
<ClCompile Include="common.cpp" />
|
||||||
|
<ClCompile Include="VersionHelper.cpp" />
|
||||||
<ClCompile Include="windows_colors.cpp" />
|
<ClCompile Include="windows_colors.cpp" />
|
||||||
<ClCompile Include="window_helpers.cpp" />
|
<ClCompile Include="window_helpers.cpp" />
|
||||||
<ClCompile Include="winstore.cpp" />
|
<ClCompile Include="winstore.cpp" />
|
||||||
|
|||||||
@@ -93,6 +93,12 @@
|
|||||||
<ClInclude Include="timeutil.h">
|
<ClInclude Include="timeutil.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="VersionHelper.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="com_object_factory.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="d2d_svg.cpp">
|
<ClCompile Include="d2d_svg.cpp">
|
||||||
@@ -150,5 +156,8 @@
|
|||||||
<ClCompile Include="notifications.cpp">
|
<ClCompile Include="notifications.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="VersionHelper.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
|
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
#include "msi_to_msix_upgrade.h"
|
#include "msi_to_msix_upgrade.h"
|
||||||
|
|
||||||
#include <msi.h>
|
#include <msi.h>
|
||||||
@@ -12,6 +15,8 @@
|
|||||||
#include <winrt/Windows.Web.Http.h>
|
#include <winrt/Windows.Web.Http.h>
|
||||||
#include <winrt/Windows.Web.Http.Headers.h>
|
#include <winrt/Windows.Web.Http.Headers.h>
|
||||||
|
|
||||||
|
#include "VersionHelper.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const wchar_t* POWER_TOYS_UPGRADE_CODE = L"{42B84BF7-5FBF-473B-9C8B-049DC16F7708}";
|
const wchar_t* POWER_TOYS_UPGRADE_CODE = L"{42B84BF7-5FBF-473B-9C8B-049DC16F7708}";
|
||||||
@@ -104,13 +109,18 @@ std::future<std::optional<new_version_download_info>> check_for_new_github_relea
|
|||||||
auto new_version = json_body.GetNamedString(L"tag_name");
|
auto new_version = json_body.GetNamedString(L"tag_name");
|
||||||
winrt::Windows::Foundation::Uri release_page_uri{ json_body.GetNamedString(L"html_url") };
|
winrt::Windows::Foundation::Uri release_page_uri{ json_body.GetNamedString(L"html_url") };
|
||||||
|
|
||||||
const auto current_version = get_product_version();
|
VersionHelper github_version(winrt::to_string(new_version));
|
||||||
if (new_version == current_version)
|
|
||||||
|
VersionHelper current_version(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION);
|
||||||
|
|
||||||
|
if (current_version > github_version)
|
||||||
{
|
{
|
||||||
co_return std::nullopt;
|
co_return std::nullopt;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
co_return new_version_download_info{ std::move(release_page_uri), new_version.c_str() };
|
{
|
||||||
|
co_return new_version_download_info{ std::move(release_page_uri), new_version.c_str() };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -98,6 +98,7 @@
|
|||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
<TreatWarningAsError>true</TreatWarningAsError>
|
||||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
<AdditionalOptions>/await %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/await %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
<AdditionalIncludeDirectories>../;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@@ -118,6 +119,7 @@
|
|||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
<AdditionalIncludeDirectories>../;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@@ -136,6 +138,7 @@
|
|||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
<TreatWarningAsError>true</TreatWarningAsError>
|
||||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||||
<AdditionalOptions>/await %(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>/await %(AdditionalOptions)</AdditionalOptions>
|
||||||
|
<AdditionalIncludeDirectories>../;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
@@ -156,6 +159,7 @@
|
|||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||||
|
<AdditionalIncludeDirectories>../;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
|
|||||||
Reference in New Issue
Block a user