Skip to content

Commit

Permalink
Merge branch 'feature/rewrite'
Browse files Browse the repository at this point in the history
  • Loading branch information
reagcz committed Nov 5, 2024
2 parents 4867fd7 + c2a6df7 commit e0a9f60
Show file tree
Hide file tree
Showing 67 changed files with 3,277 additions and 600 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# Default severity for analyzer diagnostics with category 'CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator'
dotnet_analyzer_diagnostic.category-CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator.severity = none
82 changes: 82 additions & 0 deletions .github/workflows/cd-winui.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Release WinUI

on:
workflow_dispatch:
inputs:
version:
description: 'Version'
required: true

jobs:
build:
runs-on: windows-latest

env:
App_Packages_Archive: IdeapadToolkit.WinUI.zip
License_Path: IdeapadToolkit.WinUI\Properties\PublishProfiles\3RD_PARTY_LICENSES.txt
App_Publish_Directory: bin\win-x64\publish\win-x64
App_Project_Directory: IdeapadToolkit.WinUI\
Solution_Path: IdeapadToolkit.sln
Project_Path: IdeapadToolkit.WinUI\IdeapadToolkit.WinUI3.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
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'

# Add MsBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/[email protected]

# 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=win-x64

# Copy license file to the publish directory
- name: Copy license file to the publish directory
run: Copy-Item -Path $env:License_Path -Destination $env:App_Project_Directory\$env:App_Publish_Directory\

- name: Remove all *.pdb files
run: Remove-Item -Path $env:App_Project_Directory\$env:App_Publish_Directory\*.pdb -Force

# 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: true

# 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
72 changes: 72 additions & 0 deletions IdeapadToolkit.Core/Helpers/Win32.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.Runtime.InteropServices;
using static IdeapadToolkit.Core.Services.UEFISettingsService;

namespace IdeapadToolkit.Core.Helpers
{
internal partial class Win32
{
[LibraryImport("kernel32.dll")]
public static partial nint OpenProcess(
int dwDesiredAccess,
[MarshalAs(UnmanagedType.Bool)]
bool bInheritHandle,
int dwProcessId);

[LibraryImport("kernel32.dll", SetLastError = true)]
public static partial int GetFirmwareEnvironmentVariableExW([MarshalAs(UnmanagedType.LPWStr)] string lpName, [MarshalAs(UnmanagedType.LPWStr)] string lpGuid, ref LenovoFlipToBootSwInterface pBuffer, int nSize, nint pAttribute);

[LibraryImport("kernel32.dll", SetLastError = true)]
public static partial int SetFirmwareEnvironmentVariableExW(
[MarshalAs(UnmanagedType.LPWStr)] string lpName,
[MarshalAs(UnmanagedType.LPWStr)] string lpGuid,
ref LenovoFlipToBootSwInterface pBuffer,
int nSize,
int attribute);

[LibraryImport("kernel32.dll")]
public static partial nint GetCurrentProcess();

[LibraryImport("advapi32.dll", StringMarshalling = StringMarshalling.Utf8)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool LookupPrivilegeValue(
string lpSystemName,
string lpName,
ref long lpLuid);

[LibraryImport("advapi32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool AdjustTokenPrivileges(
nint tokenHandle,
[MarshalAs(UnmanagedType.Bool)] bool disableAllPrivileges,
ref TokenPrivelege newState,
int zero,
nint null1,
nint null2);

[LibraryImport("advapi32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool OpenProcessToken(
nint processHandle,
uint desiredAccess,
ref nint tokenHandle);

[LibraryImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool GetFirmwareType(ref FirmwareType firmwareType);
}

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct TokenPrivelege
{
public int Count;
public long Luid;
public int Attr;
}
public enum FirmwareType
{
FirmwareTypeUnknown,
FirmwareTypeBios,
FirmwareTypeUefi,
FirmwareTypeMax,
}
}
15 changes: 15 additions & 0 deletions IdeapadToolkit.Core/IdeapadToolkit.Core.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="4.0.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace IdeapadToolkit.Models
{
[NativeCppClass]
[StructLayout(LayoutKind.Sequential, Size = 16)]
public struct CChargingMode
{
private long value;
}
}
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace IdeapadToolkit.Core.Models
{
[NativeCppClass]
[StructLayout(LayoutKind.Sequential, Size = 16)]
public struct CChargingMode
{
private long value;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace IdeapadToolkit.Models
{
[NativeCppClass]
[StructLayout(LayoutKind.Sequential, Size = 16)]
public struct CIntelligentCooling
{
private long value;
}
}
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace IdeapadToolkit.Core.Models
{
[NativeCppClass]
[StructLayout(LayoutKind.Sequential, Size = 16)]
public struct CIntelligentCooling
{
private long value;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace IdeapadToolkit.Models
{
[NativeCppClass]
[StructLayout(LayoutKind.Sequential, Size = 16)]
public struct CUSBBatteryCharger
{
private long value;
}
}
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace IdeapadToolkit.Core.Models
{
[NativeCppClass]
[StructLayout(LayoutKind.Sequential, Size = 16)]
public struct CUSBBatteryCharger
{
private long value;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace IdeapadToolkit.Models
{
[NativeCppClass]
[StructLayout(LayoutKind.Sequential, Size = 16)]
public struct CUSBCharger
{
private long value;
}
}
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace IdeapadToolkit.Core.Models
{
[NativeCppClass]
[StructLayout(LayoutKind.Sequential, Size = 16)]
public struct CUSBCharger
{
private long value;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace IdeapadToolkit.Models
{
public enum ChargingMode
{
Conservation = 1,
Normal = 0,
Rapid = 2
}
}
namespace IdeapadToolkit.Core.Models
{
public enum ChargingMode
{
Conservation = 1,
Normal = 0,
Rapid = 2
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace IdeapadToolkit.Models
{
public enum PowerPlan
{
IntelligentCooling = 1,
ExtremePerformance = 3,
EfficiencyMode = 2
}
}
namespace IdeapadToolkit.Core.Models
{
public enum PowerPlan
{
IntelligentCooling = 1,
ExtremePerformance = 3,
EfficiencyMode = 2
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
using System;
using System.Diagnostics;
using System.Security.Principal;

namespace IdeapadToolkit.Services
{
public class AdministratorPermissionService : IAdministratorPermissionService
{
public bool IsAdministrator
{
get
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
}

public void RelaunchAsAdmin()
{
var proc = new Process
{
StartInfo =
{FileName = Environment.ProcessPath, UseShellExecute = true, Verb = "runas", Arguments="ignoreRunning"}
};
proc.Start();
Environment.Exit(0);
}
}
}
using System.Diagnostics;
using System.Security.Principal;

namespace IdeapadToolkit.Core.Services
{
public class AdministratorPermissionService : IAdministratorPermissionService
{
public bool IsAdministrator
{
get
{
var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
}

public void RelaunchAsAdmin()
{
var proc = new Process
{
StartInfo =
{FileName = Environment.ProcessPath, UseShellExecute = true, Verb = "runas", Arguments="ignoreRunning"}
};
proc.Start();
Environment.Exit(0);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace IdeapadToolkit.Services
{
public interface IAdministratorPermissionService
{
public bool IsAdministrator { get; }
public void RelaunchAsAdmin();
}
}
namespace IdeapadToolkit.Core.Services
{
public interface IAdministratorPermissionService
{
public bool IsAdministrator { get; }
public void RelaunchAsAdmin();
}
}
Loading

0 comments on commit e0a9f60

Please sign in to comment.