Skip to content

Commit

Permalink
Merge pull request #48 from Leo-Corporation/vNext
Browse files Browse the repository at this point in the history
Version 1.1.0.2212
  • Loading branch information
lpeyr authored Dec 4, 2022
2 parents 4d4ae7c + 4925dad commit f1a71e3
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
build:
strategy:
matrix:
dotnet: ['5.0.x', '6.0.x']
dotnet: ['5.0.x', '6.0.x', '7.0.x']
os: ['ubuntu-latest', 'windows-latest']
runs-on: ${{ matrix.os }}
name: .NET ${{ matrix.dotnet }} on ${{ matrix.os }} sample
Expand Down
23 changes: 23 additions & 0 deletions PeyrSharp.Core/Converters/Time.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,28 @@ public static class Time
TimeUnits.Days => d,// Return the expected value
_ => d,
};

/// <summary>
/// Converts Unix Time to a <see cref="DateTime"/>.
/// </summary>
/// <param name="unixTime">The Unix Time.</param>
/// <returns>The unix time converted to <see cref="DateTime"/>.</returns>
public static DateTime UnixTimeToDateTime(int unixTime)
{
DateTime dtDateTime = new(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); // Create a date
dtDateTime = dtDateTime.AddSeconds(unixTime).ToLocalTime(); // Add the seconds
return dtDateTime; // Return the result
}

/// <summary>
/// Converts a <see cref="DateTime"/> to Unix Time.
/// </summary>
/// <param name="dateTime">The <see cref="DateTime"/> to convert.</param>
/// <returns>The converted <see cref="DateTime"/> in unix time.</returns>
public static int DateTimeToUnixTime(DateTime dateTime)
{
DateTime dtDateTime = new(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); // Create a date
return (int)dateTime.Subtract(dtDateTime).TotalSeconds; // Return the result
}
}
}
10 changes: 6 additions & 4 deletions PeyrSharp.Core/PeyrSharp.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Core</Title>
<Version>1.0.0.2211</Version>
<Version>1.1.0.2212</Version>
<Authors>Léo Corporation</Authors>
<Description>Core methods and features of PeyrSharp.</Description>
<Copyright>© 2022</Copyright>
Expand All @@ -16,6 +16,8 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Added ``UnixTimeToDateTime()`` method (#43)
- Added ``DateTimeToUnixTime()`` method (#43)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -30,8 +32,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.0.0.2211" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.0.0.2211" />
<PackageReference Include="PeyrSharp.Enums" Version="1.1.0.2212" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.1.0.2212" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions PeyrSharp.Enums/PeyrSharp.Enums.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<Title>PeyrSharp.Enums</Title>
Expand All @@ -11,7 +11,7 @@
<PackageProjectUrl>https://github.com/Leo-Corporation/PeyrSharp</PackageProjectUrl>
<RepositoryUrl>https://github.com/Leo-Corporation/PeyrSharp</RepositoryUrl>
<PackageTags>enums;c-sharp;dotnet;vb;peyrsharp;leo corp</PackageTags>
<Version>1.0.0.2211</Version>
<Version>1.1.0.2212</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
Expand Down
74 changes: 74 additions & 0 deletions PeyrSharp.Env/FileSys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using PeyrSharp.Enums;
using System;
using System.IO;
using System.Linq;
using System.Runtime.Versioning;
using System.Threading.Tasks;

Expand Down Expand Up @@ -167,5 +168,78 @@ public static bool CanWriteFile(string filePath)
/// Gets the <c>%APPDATA%</c> path.
/// </summary>
public static string AppDataPath => Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

/// <summary>
/// Returns the directory where the app is executed.
/// </summary>
public static string CurrentAppDirectory => Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

/// <summary>
/// Gets the drive with the lowest free space available.
/// </summary>
/// <returns>A <see cref="DriveInfo"/> which contains the information of the drive.</returns>
public static DriveInfo DriveWithLowestFreeSpace
{
get
{
var drives = DriveInfo.GetDrives(); // Get all drives
drives = drives.Where(x => x.DriveType != DriveType.CDRom).ToArray(); // Remove CD-ROM
return drives.OrderBy(x => x.TotalFreeSpace).First(); // Return the drive with the lowest free space
}
}

/// <summary>
/// Gets the drive with the highest free space available.
/// </summary>
/// <returns>A <see cref="DriveInfo"/> which contains the information of the drive.</returns>
public static DriveInfo DriveWithHighestFreeSpace
{
get
{
var drives = DriveInfo.GetDrives(); // Get all drives
drives = drives.Where(x => x.DriveType != DriveType.CDRom).ToArray(); // Remove CD-ROM
return drives.OrderByDescending(x => x.TotalFreeSpace).First(); // Return the drive with the highest free space
}
}

/// <summary>
/// Gets if a specified drive is a CD/DVD-ROM.
/// </summary>
/// <param name="driveInfo">The drive to check.</param>
/// <returns><see langword="true"/> if the drive is an optical drive; <see langword="false"/> if it isn't.</returns>
public static bool IsDriveOpticalDrive(DriveInfo driveInfo) => driveInfo.DriveType == DriveType.CDRom;

/// <summary>
/// Gets the appropriate <see cref="StorageUnits"/> to use depending of the total size of the drive.
/// </summary>
/// <param name="driveInfo">The drive to get the unit of.</param>
/// <returns>The appropriate unit of the specified drive.</returns>
public static StorageUnits GetDriveStorageUnit(DriveInfo driveInfo)
{
if (driveInfo.TotalSize >= Math.Pow(1024, 5))
{
return StorageUnits.Petabyte;
}
else if (driveInfo.TotalSize >= Math.Pow(1024, 4))
{
return StorageUnits.Terabyte;
}
else if (driveInfo.TotalSize >= 1073741824)
{
return StorageUnits.Gigabyte;
}
else if (driveInfo.TotalSize >= 1048576)
{
return StorageUnits.Megabyte;
}
else if (driveInfo.TotalSize >= 1024)
{
return StorageUnits.Kilobyte;
}
else
{
return StorageUnits.Byte;
}
}
}
}
11 changes: 8 additions & 3 deletions PeyrSharp.Env/PeyrSharp.Env.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Env</Title>
<Version>1.0.0.2211</Version>
<Version>1.1.0.2212</Version>
<Authors>Léo Corporation</Authors>
<Description>Environment-related methods of PeyrSharp.</Description>
<Copyright>© 2022</Copyright>
Expand All @@ -16,6 +16,11 @@
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Added the possibility to get current directory (#38)
- Added the possibility to get the drive with the lowest available free space (#39)
- Added the possibility to get the drive with the highest available free space (#40)
- Added the possibility to check if a drive is a DVD/CD-ROM (#41)
- Added the possibility to get the `StorageUnits` of a drive (#42)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -30,6 +35,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.0.0.2211" />
<PackageReference Include="PeyrSharp.Enums" Version="1.1.0.2212" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>PeyrSharp.Exceptions</Title>
<Version>1.0.0.2211</Version>
<Version>1.1.0.2212</Version>
<Company>Léo Corporation</Company>
<Description>Exceptions of PeyrSharp.</Description>
<Copyright>© 2022</Copyright>
Expand Down
6 changes: 3 additions & 3 deletions PeyrSharp.Extensions/PeyrSharp.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Extensions</Title>
<Version>1.0.0.2211</Version>
<Version>1.1.0.2212</Version>
<Authors>Léo Corporation</Authors>
<Description>Extensions methods of PeyrSharp.</Description>
<Copyright>© 2022</Copyright>
Expand All @@ -30,7 +30,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.0.0.2211" />
<PackageReference Include="PeyrSharp.Enums" Version="1.1.0.2212" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0-windows;net6.0-windows</TargetFrameworks>
<TargetFrameworks>net5.0-windows;net6.0-windows;net7.0-windows</TargetFrameworks>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.UiHelpers</Title>
<Version>1.0.0.2211</Version>
<Version>1.1.0.2212</Version>
<Authors>Léo Corporation</Authors>
<Description>Useful helpers for Windows Forms and Windows Presentation Framework.</Description>
<Copyright>© 2022</Copyright>
Expand All @@ -33,7 +33,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.0.0.2211" />
<PackageReference Include="PeyrSharp.Enums" Version="1.1.0.2212" />
</ItemGroup>

</Project>
16 changes: 8 additions & 8 deletions PeyrSharp/PeyrSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net6.0;net5.0-windows;net6.0-windows</TargetFrameworks>
<TargetFrameworks>net5.0;net6.0;net5.0-windows;net6.0-windows;net7.0;net7.0-windows</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp</Title>
<Version>1.0.0.2211</Version>
<Version>1.1.0.2212</Version>
<Authors>Léo Corporation</Authors>
<Copyright>© 2022</Copyright>
<Description>A C# library designed to make developers' job easier.</Description>
Expand All @@ -30,12 +30,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Core" Version="1.0.0.2211" />
<PackageReference Include="PeyrSharp.Enums" Version="1.0.0.2211" />
<PackageReference Include="PeyrSharp.Env" Version="1.0.0.2211" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.0.0.2211" />
<PackageReference Include="PeyrSharp.Extensions" Version="1.0.0.2211" />
<PackageReference Condition="'$(TargetPlatformIdentifier)' == 'Windows'" Include="PeyrSharp.UiHelpers" Version="1.0.0.2211" />
<PackageReference Include="PeyrSharp.Core" Version="1.1.0.2212" />
<PackageReference Include="PeyrSharp.Enums" Version="1.1.0.2212" />
<PackageReference Include="PeyrSharp.Env" Version="1.1.0.2212" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.1.0.2212" />
<PackageReference Include="PeyrSharp.Extensions" Version="1.1.0.2212" />
<PackageReference Condition="'$(TargetPlatformIdentifier)' == 'Windows'" Include="PeyrSharp.UiHelpers" Version="1.1.0.2212" />
</ItemGroup>

</Project>

0 comments on commit f1a71e3

Please sign in to comment.