mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-12 02:09:24 +08:00
[Settings] Update version in General Settings (#2601)
* Update version in General Settings * Set version in settings.json file * Only overwrite the settings.json file if it is newer than the old version. * Fix tests * Fix test names and added comment
This commit is contained in:
parent
d401474981
commit
7fc140af01
@ -51,7 +51,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
@ -59,7 +59,8 @@
|
||||
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<AdditionalIncludeDirectories>inc;telemetry;..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@ -70,13 +71,14 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<AdditionalIncludeDirectories>inc;telemetry;..\..\deps\cpprestsdk\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
@ -84,20 +86,18 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\common.h" />
|
||||
<ClInclude Include="..\keyboard_layout.h" />
|
||||
<ClInclude Include="..\keyboard_layout_impl.h" />
|
||||
<ClInclude Include="..\pch.h" />
|
||||
<ClInclude Include="..\two_way_pipe_message_ipc.h" />
|
||||
<ClInclude Include="..\two_way_pipe_message_ipc_impl.h" />
|
||||
<ClInclude Include="framework.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\common.cpp" />
|
||||
<ClCompile Include="..\keyboard_layout.cpp" />
|
||||
<ClCompile Include="..\pch.cpp" />
|
||||
<ClCompile Include="..\two_way_pipe_message_ipc.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
@ -15,12 +15,6 @@
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="framework.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="pch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\keyboard_layout.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
@ -33,16 +27,25 @@
|
||||
<ClInclude Include="..\two_way_pipe_message_ipc_impl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\common.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\pch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\keyboard_layout.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\two_way_pipe_message_ipc.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\common.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\pch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,3 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
@ -1,5 +0,0 @@
|
||||
// pch.cpp: source file corresponding to the pre-compiled header
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
|
@ -1,13 +0,0 @@
|
||||
// pch.h: This is a precompiled header file.
|
||||
// Files listed below are compiled only once, improving build performance for future builds.
|
||||
// This also affects IntelliSense performance, including code completion and many code browsing features.
|
||||
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
|
||||
// Do not add files here that you will be updating frequently as this negates the performance advantage.
|
||||
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
// add headers that you want to pre-compile here
|
||||
#include "framework.h"
|
||||
|
||||
#endif //PCH_H
|
@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "..\keyboard_layout.h"
|
||||
#include "..\two_way_pipe_message_ipc.h"
|
||||
#include <msclr\marshal.h>
|
||||
#include <msclr\marshal_cppstd.h>
|
||||
#include <functional>
|
||||
#include "..\keyboard_layout.h"
|
||||
#include "..\two_way_pipe_message_ipc.h"
|
||||
#include "..\common.h"
|
||||
|
||||
using namespace System;
|
||||
using namespace System::Runtime::InteropServices;
|
||||
@ -103,4 +104,14 @@ public
|
||||
_callback(gcnew String(msg.c_str()));
|
||||
}
|
||||
};
|
||||
|
||||
public
|
||||
ref class CommonManaged
|
||||
{
|
||||
public:
|
||||
static String^ GetProductVersion()
|
||||
{
|
||||
return gcnew String(get_product_version().c_str());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -73,7 +73,7 @@
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>WindowsApp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>
|
||||
</DelayLoadDLLs>
|
||||
</Link>
|
||||
@ -89,7 +89,7 @@
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>WindowsApp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<DelayLoadDLLs>
|
||||
</DelayLoadDLLs>
|
||||
</Link>
|
||||
|
@ -59,7 +59,7 @@ namespace Microsoft.PowerToys.Settings.UI.Lib
|
||||
this.AutoDownloadUpdates = false;
|
||||
this.Theme = "system";
|
||||
this.SystemTheme = "light";
|
||||
this.PowertoysVersion = "v0.15.3";
|
||||
this.PowertoysVersion = interop.CommonManaged.GetProductVersion();
|
||||
this.Enabled = new EnabledModules();
|
||||
this.CustomActionName = string.Empty;
|
||||
}
|
||||
|
@ -5,9 +5,11 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib.CustomAction;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
|
||||
@ -78,5 +80,42 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.Utilities
|
||||
{
|
||||
return layoutMap.GetKeyName(key);
|
||||
}
|
||||
|
||||
public static string GetProductVersion()
|
||||
{
|
||||
return interop.CommonManaged.GetProductVersion();
|
||||
}
|
||||
|
||||
public static int CompareVersions(string version1, string version2)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Split up the version strings into int[]
|
||||
// Example: v10.0.2 -> {10, 0, 2};
|
||||
var v1 = version1.Substring(1).Split('.').Select(int.Parse).ToArray();
|
||||
var v2 = version2.Substring(1).Split('.').Select(int.Parse).ToArray();
|
||||
|
||||
if (v1.Count() != 3 || v2.Count() != 3)
|
||||
{
|
||||
throw new FormatException();
|
||||
}
|
||||
|
||||
if (v1[0] - v2[0] != 0)
|
||||
{
|
||||
return v1[0] - v2[0];
|
||||
}
|
||||
|
||||
if (v1[1] - v2[1] != 0)
|
||||
{
|
||||
return v1[1] - v2[1];
|
||||
}
|
||||
|
||||
return v1[2] - v2[2];
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new FormatException("Bad product version format");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels.Commands;
|
||||
using Microsoft.PowerToys.Settings.UI.Views;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
|
||||
using Windows.Data.Html;
|
||||
using Windows.System;
|
||||
using Windows.UI.Popups;
|
||||
using Windows.UI.Xaml;
|
||||
@ -32,6 +34,18 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
try
|
||||
{
|
||||
GeneralSettingsConfigs = SettingsUtils.GetSettings<GeneralSettings>(string.Empty);
|
||||
|
||||
if (Helper.CompareVersions(GeneralSettingsConfigs.PowertoysVersion, Helper.GetProductVersion()) < 0)
|
||||
{
|
||||
// Update settings
|
||||
GeneralSettingsConfigs.PowertoysVersion = Helper.GetProductVersion();
|
||||
SettingsUtils.SaveSettings(GeneralSettingsConfigs.ToJsonString(), string.Empty);
|
||||
}
|
||||
}
|
||||
catch (FormatException e)
|
||||
{
|
||||
// If there is an issue with the version number format, don't migrate settings.
|
||||
Debug.WriteLine(e.Message);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -216,6 +230,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public string PowerToysVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return Helper.GetProductVersion();
|
||||
}
|
||||
}
|
||||
|
||||
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
// Notify UI of property change
|
||||
|
@ -89,7 +89,7 @@
|
||||
Style="{StaticResource SettingsGroupTitleStyle}"
|
||||
Margin="{StaticResource XSmallBottomMargin}"/>
|
||||
|
||||
<TextBlock Text="Version 0.15.2"
|
||||
<TextBlock Text="{x:Bind ViewModel.PowerToysVersion }"
|
||||
FontWeight="Bold"
|
||||
Margin="{StaticResource SmallTopMargin}" />
|
||||
|
||||
|
@ -119,6 +119,7 @@
|
||||
<SDKReference Include="TestPlatform.Universal, Version=$(UnitTestPlatformVersion)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ModelsTests\HelperTest.cs" />
|
||||
<Compile Include="ViewModelTests\ImageResizer.cs" />
|
||||
<Compile Include="ModelsTests\BasePTModuleSettingsTest.cs" />
|
||||
<Compile Include="ModelsTests\BasePTSettingsTest.cs" />
|
||||
|
@ -0,0 +1,73 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Microsoft.PowerToys.Settings.UI.Lib.Utilities;
|
||||
using System;
|
||||
|
||||
namespace CommonLibTest
|
||||
{
|
||||
[TestClass]
|
||||
public class HelperTest
|
||||
{
|
||||
public static void TestStringIsSmaller(string v1, string v2)
|
||||
{
|
||||
var res = Helper.CompareVersions(v1, v2);
|
||||
Assert.IsTrue(res < 0);
|
||||
}
|
||||
|
||||
|
||||
public static void TestStringsAreEqual(string v1, string v2)
|
||||
{
|
||||
var res = Helper.CompareVersions(v1, v2);
|
||||
Assert.IsTrue(res == 0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Helper_CompareVersions_ShouldBeEqual_WhenSuccessful()
|
||||
{
|
||||
TestStringsAreEqual("v0.0.0", "v0.0.0");
|
||||
TestStringsAreEqual("v0.1.1", "v0.1.1");
|
||||
TestStringsAreEqual("v1.1.1", "v1.1.1");
|
||||
TestStringsAreEqual("v1.999.99", "v1.999.99");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Helper_CompareVersions_ShouldBeSmaller_WhenSuccessful()
|
||||
{
|
||||
TestStringIsSmaller("v0.0.0", "v0.0.1");
|
||||
TestStringIsSmaller("v0.0.0", "v0.1.0");
|
||||
TestStringIsSmaller("v0.0.0", "v1.0.0");
|
||||
TestStringIsSmaller("v1.0.1", "v1.0.2");
|
||||
TestStringIsSmaller("v1.1.1", "v1.1.2");
|
||||
TestStringIsSmaller("v1.1.1", "v1.2.0");
|
||||
TestStringIsSmaller("v1.999.99", "v2.0.0");
|
||||
TestStringIsSmaller("v1.0.99", "v1.2.0");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(FormatException))]
|
||||
public void Helper_CompareVersions_ShouldThrowBadFormat_WhenNoVersionString()
|
||||
{
|
||||
Helper.CompareVersions("v0.0.1", "");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(FormatException))]
|
||||
public void Helper_CompareVersions_ShouldThrowBadFormat_WhenShortVersionString()
|
||||
{
|
||||
Helper.CompareVersions("v0.0.1", "v0.1");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(FormatException))]
|
||||
public void Helper_CompareVersions_ShouldThrowBadFormat_WhenLongVersionString()
|
||||
{
|
||||
Helper.CompareVersions("v0.0.1", "v0.0.0.1");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(FormatException))]
|
||||
public void Helper_CompareVersions_ShouldThrowBadFormat_WhenItIsNotAVersionString()
|
||||
{
|
||||
Helper.CompareVersions("v0.0.1", "HelloWorld");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user