From 5781e0ee627924f86f93e573a78f4b89a9e62751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Havl=C3=AD=C4=8Dek?= Date: Wed, 16 Nov 2022 01:32:04 +0100 Subject: [PATCH 1/5] Fix compatibility with other powerbattery.dll versions --- IdeapadToolkit/IdeapadToolkit.csproj | 2 +- .../Services/LenovoPowerSettingsService.cs | 28 +++++++++---------- .../LenovoPowerSettingsServiceTests.cs | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/IdeapadToolkit/IdeapadToolkit.csproj b/IdeapadToolkit/IdeapadToolkit.csproj index 514abdf..254c7d3 100644 --- a/IdeapadToolkit/IdeapadToolkit.csproj +++ b/IdeapadToolkit/IdeapadToolkit.csproj @@ -34,7 +34,7 @@ - PreserveNewest + Always diff --git a/IdeapadToolkit/Services/LenovoPowerSettingsService.cs b/IdeapadToolkit/Services/LenovoPowerSettingsService.cs index 5b378de..a49afb5 100644 --- a/IdeapadToolkit/Services/LenovoPowerSettingsService.cs +++ b/IdeapadToolkit/Services/LenovoPowerSettingsService.cs @@ -13,51 +13,51 @@ namespace IdeapadToolkit.Services { public class LenovoPowerSettingsService : ILenovoPowerSettingsService { - [DllImport("PowerBattery.dll", EntryPoint = "#142", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "?SetITSMode@CIntelligentCooling@PowerBattery@@QEAAHAEAW4ITSMode@12@@Z", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int SetITSMode(ref CIntelligentCooling var1, ref PowerPlan var2); - [DllImport("PowerBattery.dll", EntryPoint = "#8", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "??0CIntelligentCooling@PowerBattery@@QEAA@XZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern CIntelligentCooling CIntelligentCooling(ref CIntelligentCooling var1); - [DllImport("PowerBattery.dll", EntryPoint = "#82", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "?GetITSMode@CIntelligentCooling@PowerBattery@@QEAAHAEAHAEAW4ITSMode@12@@Z", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int GetITSMode(ref CIntelligentCooling var1, ref int var2, ref PowerPlan var3); - [DllImport("PowerBattery.dll", EntryPoint = "#6", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "??0CChargingMode@PowerBattery@@QEAA@XZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern CChargingMode CChargingMode(ref CChargingMode var1); - [DllImport("PowerBattery.dll", EntryPoint = "#74", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "?GetChargingMode@CChargingMode@PowerBattery@@QEBAHXZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int GetChargingMode(ref CChargingMode var1); - [DllImport("PowerBattery.dll", EntryPoint = "#139", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "?SetChargingMode@CChargingMode@PowerBattery@@QEBAHH@Z", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int SetChargingMode(ref CChargingMode var1, int var2); - [DllImport("PowerBattery.dll", EntryPoint = "#16", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "??0CUSBCharger@PowerBattery@@QEAA@XZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern CUSBCharger CUSBCharger(ref CUSBCharger var1); - [DllImport("PowerBattery.dll", EntryPoint = "#14", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "??0CUSBBatteryCharger@PowerBattery@@QEAA@XZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern CUSBBatteryCharger CUSBBatteryCharger(ref CUSBBatteryCharger var1); - [DllImport("PowerBattery.dll", EntryPoint = "#107", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "?OpenOrClose@CUSBBatteryCharger@PowerBattery@@UEAAHXZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int OpenOrClose(ref CUSBBatteryCharger var1); - [DllImport("PowerBattery.dll", EntryPoint = "#108", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "?OpenOrClose@CUSBCharger@PowerBattery@@UEAAHXZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int OpenOrClose(ref CUSBCharger var1); - [DllImport("PowerBattery.dll", EntryPoint = "#106", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "?OpenFeature@CUSBCharger@PowerBattery@@UEAAHXZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int OpenFeature(ref CUSBCharger var1); - [DllImport("PowerBattery.dll", EntryPoint = "#105", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "?OpenFeature@CUSBBatteryCharger@PowerBattery@@UEAAHXZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int OpenFeature(ref CUSBBatteryCharger var1); - [DllImport("PowerBattery.dll", EntryPoint = "#53", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "?CloseFeature@CUSBCharger@PowerBattery@@UEAAHXZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int CloseFeature(ref CUSBCharger var1); - [DllImport("PowerBattery.dll", EntryPoint = "#52", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + [DllImport("PowerBattery.dll", EntryPoint = "?CloseFeature@CUSBBatteryCharger@PowerBattery@@UEAAHXZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int CloseFeature(ref CUSBBatteryCharger var1); diff --git a/IdeapadToolkitTests/Services/LenovoPowerSettingsServiceTests.cs b/IdeapadToolkitTests/Services/LenovoPowerSettingsServiceTests.cs index 77f804f..0a39cfc 100644 --- a/IdeapadToolkitTests/Services/LenovoPowerSettingsServiceTests.cs +++ b/IdeapadToolkitTests/Services/LenovoPowerSettingsServiceTests.cs @@ -58,7 +58,7 @@ public void AlwaysOnUsbBattryRandomTest() } [TestMethod()] - private void SetChargingModeRandomTest() + public void SetChargingModeRandomTest() { _service.SetChargingMode(Models.ChargingMode.Normal); Assert.IsTrue(_service.GetChargingMode() == Models.ChargingMode.Normal); From e03fbfdb3ce743359d83f9c1bebe0d975b0c2352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Havl=C3=AD=C4=8Dek?= Date: Thu, 17 Nov 2022 19:58:59 +0100 Subject: [PATCH 2/5] Add support for newer versions of powerbattery.dll --- .../Services/LenovoPowerSettingsService.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/IdeapadToolkit/Services/LenovoPowerSettingsService.cs b/IdeapadToolkit/Services/LenovoPowerSettingsService.cs index a49afb5..32bfb65 100644 --- a/IdeapadToolkit/Services/LenovoPowerSettingsService.cs +++ b/IdeapadToolkit/Services/LenovoPowerSettingsService.cs @@ -32,10 +32,13 @@ public class LenovoPowerSettingsService : ILenovoPowerSettingsService [DllImport("PowerBattery.dll", EntryPoint = "?GetChargingMode@CChargingMode@PowerBattery@@QEBAHXZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int GetChargingMode(ref CChargingMode var1); - [DllImport("PowerBattery.dll", EntryPoint = "?SetChargingMode@CChargingMode@PowerBattery@@QEBAHH@Z", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern int SetChargingMode(ref CChargingMode var1, int var2); + [DllImport("PowerBattery.dll", EntryPoint = "?SetChargingMode@CChargingMode@PowerBattery@@QEBAHH_N@Z", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] + // I don't know what the newly added boolean does, but it doesn't seem to matter + internal static extern int SetChargingModeFallBack(ref CChargingMode var1, int var2, bool var3); + [DllImport("PowerBattery.dll", EntryPoint = "??0CUSBCharger@PowerBattery@@QEAA@XZ", CallingConvention = CallingConvention.Cdecl, SetLastError = true)] internal static extern CUSBCharger CUSBCharger(ref CUSBCharger var1); @@ -90,7 +93,14 @@ public void SetChargingMode(ChargingMode chargingMode) { CChargingMode instance = new(); instance = CChargingMode(ref instance); - _ = SetChargingMode(ref instance, (int)chargingMode); + try + { + _ = SetChargingMode(ref instance, (int)chargingMode); + } + catch (SystemException) + { + _ = SetChargingModeFallBack(ref instance, (int)chargingMode, false); + } } public bool IsAlwaysOnUsbEnabled() From 5b8b066dd114a3159a05927a60105e69fd148818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Havl=C3=AD=C4=8Dek?= Date: Thu, 17 Nov 2022 20:48:11 +0100 Subject: [PATCH 3/5] Add logging, improve exception handling --- IdeapadToolkit/App.xaml.cs | 24 ++++- IdeapadToolkit/IdeapadToolkit.csproj | 2 + .../Services/UEFISettingsService.cs | 17 +++- .../ViewModels/LenovoSettingsViewModel.cs | 98 +++++++++++++++---- .../IdeapadToolkitTests.csproj | 1 + .../Services/UEFISettingsServiceTests.cs | 5 +- 6 files changed, 121 insertions(+), 26 deletions(-) diff --git a/IdeapadToolkit/App.xaml.cs b/IdeapadToolkit/App.xaml.cs index ff7eaa7..cabb604 100644 --- a/IdeapadToolkit/App.xaml.cs +++ b/IdeapadToolkit/App.xaml.cs @@ -13,7 +13,9 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using Serilog; using System.Windows; +using Serilog.Core; namespace IdeapadToolkit { @@ -23,9 +25,21 @@ namespace IdeapadToolkit public partial class App : Application { private Container _container; + private ILogger _logger; - public static void ConfigureServices(Container container) + public void ConfigureServices(Container container) { + // For later use + var logLevel = new LoggingLevelSwitch(); + logLevel.MinimumLevel = Serilog.Events.LogEventLevel.Error; + var loggerConfig = new LoggerConfiguration() + .MinimumLevel.ControlledBy(logLevel) + .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7, levelSwitch: logLevel); + var logger = _logger = loggerConfig.CreateLogger(); + + container.RegisterInstance(logger); + container.RegisterInstance(logLevel); + container.RegisterSingleton(); container.RegisterSingleton(); container.RegisterSingleton(); @@ -46,6 +60,7 @@ protected override void OnStartup(StartupEventArgs e) base.OnStartup(e); Container container = _container = new Container(); ConfigureServices(container); + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; bool exists = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Environment.ProcessPath)).Length > 1; if (exists && !e.Args.Contains("ignoreRunning")) { @@ -67,12 +82,17 @@ protected override void OnStartup(StartupEventArgs e) { ShowMainWindow(null, null); } - + var iconview = _container.GetInstance(); iconview.MakeVisible(); iconview.TrayIconClicked += ShowMainWindow; } + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + _logger.Fatal((Exception)e.ExceptionObject, "Unhandled exception"); + } + public void ShowMainWindow(object? sender, EventArgs? e) { if (App.Current.MainWindow == null) diff --git a/IdeapadToolkit/IdeapadToolkit.csproj b/IdeapadToolkit/IdeapadToolkit.csproj index 254c7d3..0a3e159 100644 --- a/IdeapadToolkit/IdeapadToolkit.csproj +++ b/IdeapadToolkit/IdeapadToolkit.csproj @@ -16,6 +16,8 @@ + + diff --git a/IdeapadToolkit/Services/UEFISettingsService.cs b/IdeapadToolkit/Services/UEFISettingsService.cs index cb26356..82a88dd 100644 --- a/IdeapadToolkit/Services/UEFISettingsService.cs +++ b/IdeapadToolkit/Services/UEFISettingsService.cs @@ -1,4 +1,5 @@ using IdeapadToolkitService.Helpers; +using Serilog; using System; using System.Collections.Generic; using System.Linq; @@ -14,8 +15,13 @@ public class UEFISettingsService : IUEFISettingsService private static readonly string Guid = "{D743491E-F484-4952-A87D-8D5DD189B70C}"; private static readonly string ScopeName = "FBSWIF"; private static readonly int ScopeAttribute = 7; + private readonly ILogger _logger; - private static bool SetPrivilege(bool enable) + public UEFISettingsService(ILogger logger) + { + this._logger = logger; + } + private bool SetPrivilege(bool enable) { try { @@ -37,8 +43,9 @@ private static bool SetPrivilege(bool enable) return false; } } - catch (Exception) + catch (Exception ex) { + _logger.Error(ex, "Exception while getting UEFI privilege"); return false; } return true; @@ -68,8 +75,9 @@ public bool GetFlipToBootStatus() dataFromUefi = lastWin32Error * -1; } } - catch (Exception) + catch (Exception ex) { + _logger.Error(ex, "Exception while getting UEFI FlipToBoot status"); } finally { @@ -100,8 +108,9 @@ public int SetFlipToBootStatus(bool newStatus) var res = (Win32.SetFirmwareEnvironmentVariableExW(ScopeName, Guid, ref structure, Marshal.SizeOf(), ScopeAttribute)); if (res != 0) return 0; } - catch (Exception) + catch (Exception ex) { + _logger.Error(ex, "Error while setting UEFI FlipToBoot status"); } finally { _ = SetPrivilege(false); } return num1; diff --git a/IdeapadToolkit/ViewModels/LenovoSettingsViewModel.cs b/IdeapadToolkit/ViewModels/LenovoSettingsViewModel.cs index 3e18622..c6bf621 100644 --- a/IdeapadToolkit/ViewModels/LenovoSettingsViewModel.cs +++ b/IdeapadToolkit/ViewModels/LenovoSettingsViewModel.cs @@ -3,6 +3,7 @@ using IdeapadToolkit.Models; using IdeapadToolkit.Services; using ModernWpf.Controls; +using Serilog; using System; using System.Collections.Generic; using System.Linq; @@ -14,18 +15,18 @@ namespace IdeapadToolkit.ViewModels [CommunityToolkit.Mvvm.ComponentModel.INotifyPropertyChanged] public partial class LenovoSettingsViewModel { - public LenovoSettingsViewModel(ILenovoPowerSettingsService lenovoPowerSettingsService, IUEFISettingsService uEFISettingsService, IAdministratorPermissionService administratorPermissionService) + public LenovoSettingsViewModel(ILenovoPowerSettingsService lenovoPowerSettingsService, IUEFISettingsService uEFISettingsService, IAdministratorPermissionService administratorPermissionService, ILogger logger) { _lenovoPowerSettingsService = lenovoPowerSettingsService; _uEFISettingsService = uEFISettingsService; _administratorPermissionService = administratorPermissionService; + _logger = logger; } - public void Refresh() - { - Plan = _lenovoPowerSettingsService.GetPowerPlan(); - Mode = _lenovoPowerSettingsService.GetChargingMode(); - } + private readonly ILenovoPowerSettingsService _lenovoPowerSettingsService; + private readonly IUEFISettingsService _uEFISettingsService; + private IAdministratorPermissionService _administratorPermissionService; + private readonly ILogger _logger; [ObservableProperty] [NotifyPropertyChangedFor(nameof(IsEfficientChecked), nameof(IsIntelligentCoolingChecked), nameof(IsExtremePerformanceChecked))] @@ -33,9 +34,18 @@ public void Refresh() [ObservableProperty] [NotifyPropertyChangedFor(nameof(IsConservationModeEnabled), nameof(IsNormalModeEnabled), nameof(IsRapidModeEnabled))] private ChargingMode _mode; - private readonly ILenovoPowerSettingsService _lenovoPowerSettingsService; - private readonly IUEFISettingsService _uEFISettingsService; - private IAdministratorPermissionService _administratorPermissionService; + public void Refresh() + { + try + { + Plan = _lenovoPowerSettingsService.GetPowerPlan(); + Mode = _lenovoPowerSettingsService.GetChargingMode(); + } + catch (Exception ex) + { + _logger.Error(ex, "Exception while fetching current settings"); + } + } #region PowerPlanProperties public bool IsEfficientChecked @@ -73,7 +83,16 @@ public bool IsFlipToBootEnabled { if (IsAdministrator) { - return _uEFISettingsService.GetFlipToBootStatus(); + bool res = false; + try + { + _uEFISettingsService.GetFlipToBootStatus(); + } + catch (Exception ex) + { + _logger.Error(ex, "Exception while getting FlipToBoot status"); + } + return res; } else { @@ -82,21 +101,41 @@ public bool IsFlipToBootEnabled } set { - _uEFISettingsService.SetFlipToBootStatus(value); + try + { + _uEFISettingsService.SetFlipToBootStatus(value); + } + catch (Exception ex) + { + _logger.Error(ex, "Exception while setting FlipToBoot status"); + } } } - - public bool IsAlwaysOnUsbEnabled { get { - return _lenovoPowerSettingsService.IsAlwaysOnUsbEnabled(); + try + { + return _lenovoPowerSettingsService.IsAlwaysOnUsbEnabled(); + } + catch (Exception ex) + { + _logger.Error(ex, "Error while getting Always on usb setting"); + return false; + } } set { - _lenovoPowerSettingsService.SetAlwaysOnUsb(value); + try + { + _lenovoPowerSettingsService.SetAlwaysOnUsb(value); + } + catch (Exception ex) + { + _logger.Error(ex, "Error while setting Always on usb setting"); + } OnPropertyChanged(nameof(IsAlwaysOnUsbEnabled)); } } @@ -105,11 +144,26 @@ public bool IsAlwaysOnUsbBatteryEnabled { get { - return _lenovoPowerSettingsService.IsAlwaysOnUsbBatteryEnabled(); + try + { + return _lenovoPowerSettingsService.IsAlwaysOnUsbBatteryEnabled(); + } + catch (Exception ex) + { + _logger.Error(ex, "Error while getting Always on usb battery setting"); + return false; + } } set { - _lenovoPowerSettingsService.SetAlwaysOnUsbBattery(value); + try + { + _lenovoPowerSettingsService.SetAlwaysOnUsbBattery(value); + } + catch (Exception ex) + { + _logger.Error(ex, "Error while setting Always on usb battery setting"); + } } } #endregion @@ -160,7 +214,10 @@ private void SetChargingMode(int? mode) _lenovoPowerSettingsService.SetChargingMode((ChargingMode)mode); Refresh(); } - catch { } + catch (Exception ex) + { + _logger.Error(ex, "Error while setting charging mode"); + } } [RelayCommand] @@ -189,7 +246,10 @@ private void SetPlan(int? plan) _lenovoPowerSettingsService.SetPowerPlan((PowerPlan)plan); Refresh(); } - catch { } + catch (Exception ex) + { + _logger.Error(ex, "Exception while setting power plan"); + } } } diff --git a/IdeapadToolkitTests/IdeapadToolkitTests.csproj b/IdeapadToolkitTests/IdeapadToolkitTests.csproj index ece0e86..5821355 100644 --- a/IdeapadToolkitTests/IdeapadToolkitTests.csproj +++ b/IdeapadToolkitTests/IdeapadToolkitTests.csproj @@ -10,6 +10,7 @@ + diff --git a/IdeapadToolkitTests/Services/UEFISettingsServiceTests.cs b/IdeapadToolkitTests/Services/UEFISettingsServiceTests.cs index 3e01a9a..b91094b 100644 --- a/IdeapadToolkitTests/Services/UEFISettingsServiceTests.cs +++ b/IdeapadToolkitTests/Services/UEFISettingsServiceTests.cs @@ -5,6 +5,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Moq; +using Serilog; namespace IdeapadToolkit.Services.Tests { @@ -15,7 +17,8 @@ public class UEFISettingsServiceTests [TestInitialize] public void TestInitialize() { - _service = new UEFISettingsService(); + var loggerMock = new Mock(); + _service = new UEFISettingsService(loggerMock.Object); } [TestMethod()] From 9fc00844e7a6f6ac55560f273e419d2900ab25dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Havl=C3=AD=C4=8Dek?= Date: Thu, 17 Nov 2022 20:53:26 +0100 Subject: [PATCH 4/5] Fix power plan name --- IdeapadToolkit/Views/TrayIconView.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IdeapadToolkit/Views/TrayIconView.xaml b/IdeapadToolkit/Views/TrayIconView.xaml index 1661162..5c461f9 100644 --- a/IdeapadToolkit/Views/TrayIconView.xaml +++ b/IdeapadToolkit/Views/TrayIconView.xaml @@ -25,7 +25,7 @@ 2 From 9dd1b66c5a39a28d5d9552cd6a5924cf694c2b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Havl=C3=AD=C4=8Dek?= Date: Thu, 17 Nov 2022 22:12:09 +0100 Subject: [PATCH 5/5] Add github actions workflow --- .github/workflows/cd.yml | 74 +++++++++++++++++++ .gitignore | 2 +- .../PublishProfiles/FolderProfile.pubxml | 18 +++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/cd.yml create mode 100644 IdeapadToolkit/Properties/PublishProfiles/FolderProfile.pubxml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..ee46bb9 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,74 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + description: 'Version' + required: true + +jobs: + build: + runs-on: windows-latest + + env: + App_Packages_Archive: IdeapadToolkit.zip + App_Publish_Directory: bin\Release\net6.0-windows10.0.20348.0\publish\win-x64 + App_Project_Directory: IdeapadToolkit\ + Solution_Path: IdeapadToolkit.sln + Project_Path: IdeapadToolkit\IdeapadToolkit.csproj + Actions_Allow_Unsecure_Commands: true # Allows AddPAth and SetEnv commands + Configuration: Release + RuntimeIdentifier: win-x64 + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 # avoid shallow clone so nbgv can do its work. + + # Install the .NET Core workload + - name: Install .NET Core + uses: actions/setup-dotnet@v3 + with: + dotnet-version: '6.0.x' + + # Add MsBuild to the PATH: https://github.com/microsoft/setup-msbuild + - name: Setup MSBuild.exe + uses: microsoft/setup-msbuild@v1.1 + + # Restore the application + - name: Restore the Wpf application to populate the obj folder + run: msbuild $env:Solution_Path /t:Restore /p:Configuration=$env:Configuration /p:RuntimeIdentifier=$env:RuntimeIdentifier + + # Build the Windows Application Packaging project for Prod_Store + - name: Build using the publish profile + run: dotnet publish /p:Configuration=Release /p:PublishProfile=FolderProfile + + # Create archive + - name: Create archive + run: Compress-Archive -Path $env:App_Project_Directory\$env:App_Publish_Directory\* -DestinationPath $env:App_Project_Directory\$env:App_Publish_Directory\$env:App_Packages_Archive + + # Create the release: https://github.com/actions/create-release + - name: Create release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ github.event.inputs.version }} + release_name: Release ${{ github.event.inputs.version }} + draft: false + prerelease: false + + # Upload release asset: https://github.com/actions/upload-release-asset + - name: Update release asset + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps + asset_path: ${{ env.App_Project_Directory }}\${{ env.App_Publish_Directory }}\${{ env.App_Packages_Archive }} + asset_name: ${{ env.App_Packages_Archive }} + asset_content_type: application/zip \ No newline at end of file diff --git a/.gitignore b/.gitignore index fc0509a..2408e9e 100644 --- a/.gitignore +++ b/.gitignore @@ -177,7 +177,7 @@ publish/ *.azurePubxml # Note: Comment the next line if you want to checkin your web deploy settings, # but database connection strings (with potential passwords) will be unencrypted -*.pubxml +# *.pubxml *.publishproj # Microsoft Azure Web App publish settings. Comment the next line if you want to diff --git a/IdeapadToolkit/Properties/PublishProfiles/FolderProfile.pubxml b/IdeapadToolkit/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000..c94f09a --- /dev/null +++ b/IdeapadToolkit/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,18 @@ + + + + + Release + Any CPU + bin\Release\net6.0-windows10.0.20348.0\publish\win-x64\ + FileSystem + <_TargetId>Folder + net6.0-windows10.0.20348.0 + win-x64 + false + true + true + + \ No newline at end of file