Skip to content

Commit

Permalink
Merge pull request #141 from DevyusCode/vNext
Browse files Browse the repository at this point in the history
Version 1.9.0.2309
  • Loading branch information
Leo-Peyronnet committed Aug 31, 2023
2 parents d75d285 + ee27329 commit ee68451
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 31 deletions.
11 changes: 4 additions & 7 deletions PeyrSharp.Core/PeyrSharp.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Core</Title>
<Version>1.8.0.2308</Version>
<Version>1.9.0.2309</Version>
<Authors>Devyus</Authors>
<Description>Core methods and features of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -16,10 +16,7 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Added Save() method in XmlHelper (#126)
- Added Load() method in XmlHelper (#127)
- Added Save() method in JsonHelper (#128)
- Added Load() method in JsonHelper (#129)</PackageReleaseNotes>
<PackageReleaseNotes></PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -34,8 +31,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.8.0.2308" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.8.0.2308" />
<PackageReference Include="PeyrSharp.Enums" Version="1.9.0.2309" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.9.0.2309" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion PeyrSharp.Enums/PeyrSharp.Enums.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<PackageProjectUrl>https://peyrsharp.leocorporation.dev/</PackageProjectUrl>
<RepositoryUrl>https://github.com/DevyusCode/PeyrSharp</RepositoryUrl>
<PackageTags>enums;c-sharp;dotnet;vb;peyrsharp;leo corp</PackageTags>
<Version>1.8.0.2308</Version>
<Version>1.9.0.2309</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
Expand Down
8 changes: 5 additions & 3 deletions PeyrSharp.Env/PeyrSharp.Env.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Env</Title>
<Version>1.8.0.2308</Version>
<Version>1.9.0.2309</Version>
<Authors>Devyus</Authors>
<Description>Environment-related methods of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -16,7 +16,8 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageReleaseNotes>- Added Supported OS attribute (#137)
- Added CurrentTheme property (#138)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -31,6 +32,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.8.0.2308" />
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="PeyrSharp.Enums" Version="1.9.0.2309" />
</ItemGroup>
</Project>
36 changes: 35 additions & 1 deletion PeyrSharp.Env/Sys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ MIT License
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using Microsoft.Win32;
using PeyrSharp.Enums;
using System;
using System.Collections.Generic;
Expand All @@ -32,7 +33,6 @@ MIT License
using System.Runtime.Versioning;
using System.Text.Json;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;

namespace PeyrSharp.Env
{
Expand Down Expand Up @@ -150,11 +150,23 @@ public static bool IsProcessRunning(string processName)
/// </summary>
/// <param name="packageFamilyName">The <c>PackageFamilyName</c> property.</param>
/// <param name="applicationID">The <c>Application Id</c> property in the UWP <c>AppxManifest.xml</c> file.</param>
[SupportedOSPlatform("windows")]
public static void LaunchUWPApp(string packageFamilyName, string applicationID)
{
Process.Start("explorer.exe", $@"shell:appsFolder\{packageFamilyName}!{applicationID}"); // Synthax to launch UWP apps
}

/// <summary>
/// Launches an UWP application using information from a <see cref="UwpApp"/> object.
/// </summary>
/// <param name="uwpApp">The UWP application to launch.</param>
[SupportedOSPlatform("windows")]
public static void LaunchUWPApp(UwpApp uwpApp)
{
string[] info = uwpApp.AppID.Split("!");
LaunchUWPApp(info[0], info[1]);
}

/// <summary>
/// Executes a program in administrator mode.
/// </summary>
Expand Down Expand Up @@ -229,6 +241,28 @@ public static void ExecuteAsAdmin(string filename)
/// <returns>The name of the current computer.</returns>
public static string ComputerName => Environment.MachineName;

/// <summary>
/// Gets the current theme. Only works on Windows 10/11.
/// </summary>
[SupportedOSPlatform("windows")]
public static SystemThemes CurrentTheme
{
get
{
if (CurrentWindowsVersion != WindowsVersion.Windows10 && CurrentWindowsVersion != WindowsVersion.Windows11)
{
return SystemThemes.Unknown; // Avoid errors on older OSs
}
var t = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize", "SystemUsesLightTheme", "1");
return t switch
{
0 => SystemThemes.Dark,
1 => SystemThemes.Light,
_ => SystemThemes.Unknown
}; // Return
}
}

/// <summary>
/// Terminates a process with the specified process ID.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>PeyrSharp.Exceptions</Title>
<Version>1.8.0.2308</Version>
<Version>1.9.0.2309</Version>
<Company>Devyus</Company>
<Description>Exceptions of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand Down
7 changes: 4 additions & 3 deletions PeyrSharp.Extensions/PeyrSharp.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Extensions</Title>
<Version>1.8.0.2308</Version>
<Version>1.9.0.2309</Version>
<Authors>Devyus</Authors>
<Description>Extensions methods of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -16,7 +16,8 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageReleaseNotes>- Added ToLowerAt(s) (#136)
- Added ToLowerAt(str, r) (#136)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -31,7 +32,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.8.0.2308" />
<PackageReference Include="PeyrSharp.Enums" Version="1.9.0.2309" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions PeyrSharp.Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ public static string DecryptAes(this string encrypted, string key)
/// <returns>The input string with the first letter uppercased.</returns>
public static string ToUpperAt(this string s) => string.IsNullOrEmpty(s) ? s : char.ToUpper(s[0]) + s[1..];

/// <summary>
/// Returns a new <see cref="string"/> in which the characters in a specified range of the current <see cref="string"/> are converted to lowercase.
/// </summary>
/// <param name="str">The <see cref="string"/> to modify.</param>
/// <param name="r">The range of characters to convert to lowercase.</param>
/// <returns>A <see cref="string"/> that is equivalent to the current <see cref="string"/>, but with the characters in the specified range converted to lowercase.</returns>
public static string ToLowerAt(this string str, Range r) => str[..r.Start.Value] + str.Substring(r.Start.Value, r.End.Value - r.Start.Value + 1).ToLower() + str[(r.End.Value + 1)..];

/// <summary>
/// Uppercases the first letter of a string.
/// </summary>
/// <param name="s">The string to capitalize.</param>
/// <returns>The input string with the first letter lowercased.</returns>
public static string ToLowerAt(this string s) => string.IsNullOrEmpty(s) ? s : char.ToLower(s[0]) + s[1..];

/// <summary>
/// Reverses a <see cref="string"/>.
/// </summary>
Expand Down
7 changes: 4 additions & 3 deletions PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<UseWPF>true</UseWPF>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.UiHelpers</Title>
<Version>1.8.0.2308</Version>
<Version>1.9.0.2309</Version>
<Authors>Devyus</Authors>
<Description>Useful helpers for Windows Forms and Windows Presentation Framework.</Description>
<Copyright>© 2023</Copyright>
Expand All @@ -20,7 +20,8 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageReleaseNotes>- Added WindowInfo class (#139)
- Added the possibility to get a list of opened windows (#139)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -35,7 +36,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.8.0.2308" />
<PackageReference Include="PeyrSharp.Enums" Version="1.9.0.2309" />
</ItemGroup>

</Project>
94 changes: 94 additions & 0 deletions PeyrSharp.UiHelpers/WindowHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
MIT License
Copyright (c) Devyus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace PeyrSharp.UiHelpers
{
/// <summary>
/// Provides utility methods for working with windows.
/// </summary>
public static class WindowHelpers
{
/// <summary>
/// Retrieves a list of currently visible windows.
/// </summary>
/// <returns>A list of <see cref="WindowInfo"/> objects representing the visible windows.</returns>
public static List<WindowInfo> GetWindows()
{
List<WindowInfo> windowList = new();
EnumWindows((hWnd, lParam) =>
{
if (IsWindowVisible(hWnd))
{
StringBuilder titleBuilder = new(256);
StringBuilder classNameBuilder = new(256);
GetWindowText(hWnd, titleBuilder, titleBuilder.Capacity);
GetClassName(hWnd, classNameBuilder, classNameBuilder.Capacity);
string title = titleBuilder.ToString();
string className = classNameBuilder.ToString();
windowList.Add(new WindowInfo
{
Handle = hWnd,
Name = title,
ClassName = className
});
}
return true;
}, IntPtr.Zero);

return windowList;
}

private static bool IsWindowVisible(IntPtr hWnd)
{
return IsWindowVisibleCore(hWnd) && !IsIconic(hWnd);
}

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisibleCore(IntPtr hWnd);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsIconic(IntPtr hWnd);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);

[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);

[DllImport("user32.dll")]
private static extern int GetClassName(IntPtr hWnd, StringBuilder className, int count);
}
}
49 changes: 49 additions & 0 deletions PeyrSharp.UiHelpers/WindowInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
MIT License
Copyright (c) Devyus
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using System;

namespace PeyrSharp.UiHelpers
{
/// <summary>
/// Represents information about a window.
/// </summary>
public class WindowInfo
{
/// <summary>
/// Gets or sets the handle of the window.
/// </summary>
public IntPtr Handle { get; set; }

/// <summary>
/// Gets or sets the name of the window.
/// </summary>
public string Name { get; set; }

/// <summary>
/// Gets or sets the class name of the window.
/// </summary>
public string ClassName { get; set; }
}

}
2 changes: 1 addition & 1 deletion PeyrSharp/PeyrSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public static class PeyrSharp
/// <summary>
/// The current version of PeyrSharp.
/// </summary>
public static string Version => "1.8.0.2308";
public static string Version => "1.9.0.2309";
}
}
Loading

0 comments on commit ee68451

Please sign in to comment.