Env

Introduction

To use these methods and features, do not forget to put this line of code in your "using" region:

C#

using LeoCorpLibrary;

VB

Imports LeoCorpLibrary

Env

Methods

File System

a. GetFilesCount

This function is available in version 1.6 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The GetFilesCount() method allows you to get the number of files in a specified directory. Returns an int value.

Variation 1

Env.GetFilesCount(string directory) {...}
ValueArgumentDescription
stringdirectoryDirectory where you want to get the number of files

Variation 2

Env.GetFilesCount(string directory, bool includeSubDirectories) {...}
ValueArgumentDescription
stringdirectoryDirectory where you want to get the number of files
boolincludeSubDirectoriesCount files that are located in the subdirectories

Here's an example of usage:

C#

// Without subdirectories
int fileNumber = Env.GetFilesCount(@"C:\Users");

// With subdirectories
int fileNumberWithSubDirectories = Env.GetFilesCount(@"C:\Users", true);

VB

' Without subdirectories
Dim fileNumber As Integer = Env.GetFilesCount("C:/Users")

' With subdirectories
Dim fileNumberWithSubDirectories As Integer = Env.GetFilesCount("C:/Users", True)

Go to top

b. GetDirectoriesCount

This function is available in version 1.6 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The GetDirectoryCount method allow you to get the number of directories in a specified directory. Returns a int value. It has two variation

Variation 1

Env.GetDirectoriesCount(string directory) {...}
ValueArgumentDescription
stringdirectoryDirectory where you want to get the number of directories

Variation 2

Env.GetDirectoriesCount(string directory, bool includeSubDirectories) {...}
ValueArgumentDescription
stringdirectoryDirectory where you want to get the number of directories
boolincludeSubDirectoriesAlso include directories in subdirectories

Here's an example of usage:

C#

// Without subdirectories
int directoryNumber = Env.GetDirectoriesCount(@"C:\Users");

// With subdirectories
int directoryNumberWithSubDirectories = Env.GetDirectoriesCount(@"C:\Users", true);

VB

' Without subdirectories
Dim directoryNumber As Integer = Env.GetDirectoriesCount("C:/Users")

' With subdirectories
Dim directoryNumberWithSubDirectories As Integer = Env.GetDirectoriesCount("C:/Users", True)

Go to top

c. GetTotalDriveSpace

This function is available in version 1.6 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The GetTotalDriveSpace method allow you to get the total space of a specified volume. Returns a double value.

It's in:

LeoCorpLibrary.Env.GetTotalDriveSpace()

It has two arguments:

ValueArgumentDescriptionExample
stringdriveDirectory of the volumeC:\
UnitTypeunitTypeType of unit to returnUnitType.Gigabyte

Here's an example of usage:

C#

double totalSpace = Env.GetTotalDriveSpace(@"C:\", UnitType.Gigabyte);

VB

Dim totalSpace As Double = Env.GetTotalDriveSpace("C:/", UnitType.Gigabyte)

Go to top

d. GetDriveAvailableFreeSpace

This function is available in version 1.6 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The GetDriveAvailableFreeSpace() method allows you to get the available space of specified volume. Returns a double value.

It's in:

LeoCorpLibrary.Env.GetDriveAvailableFreeSpace()

It has two arguments:

ValueArgumentDescriptionExample
stringdriveDirectory of the volumeC:\
UnitTypeunitTypeType of unit to return (MB, GB)UnitType.Gigabyte

Here's an example of usage:

C#

double freeSpace = Env.GetDriveAvailableFreeSpace(@"C:\", UnitType.Gigabyte);

VB

Dim freeSpace As Double = Env.GetDriveAvailableFreeSpace("C:/", UnitType.Gigabyte)

Go to top

e. GetOccupiedDriveSpace

This function is available in version 1.6 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The GetOccupiedDriveSpace() allows you to get the occupied drive space of specified volume. Returns a double value.

It's in:

LeoCorpLibrary.Env.GetOccupiedDriveSpace()

It has two arguments:

ValueArgumentDescriptionExample
stringdriveDirectory of the volumeC:\
UnitTypeunitTypeType of unit to return (MB, GB)UnitType.Gigabyte

Here's an example of usage:

C#

double occupiedSpace = GetOccupiedDriveSpace(@"C:\", UnitType.Gigabyte);

VB

Dim occupiedSpace As Double = GetOccupiedDriveSpace("C:/", UnitType.Gigabyte)

Go to top

f. CountFileCharacters

This function is available in version 2.1 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The CountFileCharacters() method enables you to get the number of characters in a specified file. It returns an int value.

It's in:

LeoCorpLibrary.Env.CountFileCharacters()

It has two arguments:

ValueArgumentDescription
stringfileNameThe file's location where you wanna count characters

Here's an example of usage:

C#

string filePath = @"C:\File.txt";
int characters = Env.CountFileCharacters(filePath);

VB

Dim filePath As String = "C:\\File.txt"
Dim characters As Integer = Env.CountFileCharacters(filePath)

Go to top

g. CountFileCharactersAsync

This function is available in version 2.1 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The CountFileCharactersAsync() method enables you to count the number of characters in a file, asynchronously. It returns a Task<int> value.

It's in:

LeoCorpLibrary.Env.CountFileCharactersAsync()

It has one argument:

ValueArgumentDescription
stringfileNameThe file's location where you wanna count characters

Here's an example of usage:

C#

async void CountCharacters()
{
  string filePath = @"C:\File.txt";
  int count = await Env.CountFileCharactersAsync(filePath);
}

VB

Private Async Sub CountCharacters()
    Dim filePath As String = "C:\\File.txt"
    Dim count As Integer = Await Env.CountFileCharactersAsync(filePath)
End Sub

Go to top

h. IsDirectoryHasPermission

This function is available in version 3.7 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The IsDirectoryHasPermission() method allows you to see if your program has permissions to write files/directories to a specified directory. It returns a bool value.

It's in:

LeoCorpLibrary.Env.IsDirectoryHasPermission()

It has one argument:

ValueArgumentDescription
stringfilePathThe path to the directory

Here's an example of usage:

C#

if (Env.IsDirectoryHasPermission("C:/Windows"))
{
    File.Create("C:/Windows/file.txt");
}

VB

If Env.IsDirectoryHasPermission("C:/Windows") Then
    File.Create("C:/Windows/file.txt")
End If

Go to top

i. GetOccupiedSpacePercentage

This function is available in version 4.8 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The GetOccupiedSpacePercentage() method allows you to get the occupied space percentage of specified volume. It returns a double value.

It's in:

LeoCorpLibrary.Env.GetOccupiedSpacePercentage()

It has one argument:

ValueArgumentDescriptionExample
DriveInfodriveInfoThe desired drive/volume to get the occupied space percentage ofnew DriveInfo(@"C:\")

Here's an example of usage:

C#

DriveInfo driveInfo = new DriveInfo(@"C:\");
double occupiedSpacePercentage = Env.GetOccupiedSpacePercentage(driveInfo);

// occupiedSpacePercentage is a double value between 0 and 1

VB

Dim driveInfo As DriveInfo = New DriveInfo("C:/")
Dim occupiedSpacePercentage As Double = Env.GetOccupiedSpacePercentage(driveInfo)

' occupiedSpacePercentage is a double value between 0 and 1

Go to top

j. GetDriveWithHighestFreeSpace

This function is available in version 4.9 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The GetDriveWithHighestFreeSpace() method allows you to get the drive with the highest free space. It returns a DriveInfo value.

It's in:

LeoCorpLibrary.Env.GetDriveWithHighestFreeSpace()

It doesn't have any arguments.

Here's an example of usage:

C#

DriveInfo driveInfo = Env.GetDriveWithHighestFreeSpace();
// driveInfo is the drive with the highest free space

VB

Dim driveInfo As DriveInfo = Env.GetDriveWithHighestFreeSpace()
' driveInfo is the drive with the highest free space

Go to top

k. GetDriveWithLowestFreeSpace

This function is available in version 4.9 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The GetDriveWithLowestFreeSpace() method allows you to get the drive with the lowest free space. It returns a DriveInfo value.

It's in:

LeoCorpLibrary.Env.GetDriveWithLowestFreeSpace()

It doesn't have any arguments.

Here's an example of usage:

C#

DriveInfo driveInfo = Env.GetDriveWithLowestFreeSpace();
// driveInfo is the drive with the lowest free space

VB

Dim driveInfo As DriveInfo = Env.GetDriveWithLowestFreeSpace()
' driveInfo is the drive with the lowest free space

Go to top

l. GetDriveUnitType

This function is available in version 4.9 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The GetDriveUnitType() method allows you to get the drive unit type. It returns a UnitType enum.

It's in:

LeoCorpLibrary.Env.GetDriveUnitType()

It has one argument:

ValueArgumentDescriptionExample
DriveInfodriveInfoThe desired drive/volume to get the drive unit type ofnew DriveInfo(@"C:\")

Here's an example of usage:

C#

var drives = DriveInfo.GetDrives();
for (int i = 0; i < drives.Length; i++)
{
	Console.WriteLine($"Name: {drives[i].Name}, Unit: {Env.GetDriveUnitType(drives[i])}, Size: {drives[i].TotalSize}");
}

/*
Example:
Name: C:\, Unit: GB, Size: 107374182400
*/

VB

Dim drives() As DriveInfo = DriveInfo.GetDrives()
For i = 0 To drives.Length - 1
    Console.WriteLine($"Name: {drives(i).Name}, Unit: {Env.GetDriveUnitType(drives(i))}, Size: {drives(i).TotalSize}")
Next

' Example:
' Name: C:\, Unit: GB, Size: 107374182400

Go to top

m. IsDriveOpticalDrive

This function is available in version 4.9 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The IsDriveOpticalDrive() method allows you to check if a specific drive is an optical drive. It returns a bool value.

It's in:

LeoCorpLibrary.Env.IsDriveOpticalDrive()

It has one argument:

ValueArgumentDescriptionExample
DriveInfodriveInfoThe desired drive/volume to check if it's an optical drivenew DriveInfo(@"C:\")

Here's an example of usage:

C#

var drives = DriveInfo.GetDrives();
for (int i = 0; i < drives.Length; i++)
{
    Console.WriteLine($"Name: {drives[i].Name}, IsOpticalDrive: {Env.IsDriveOpticalDrive(drives[i])}");
}

/*
Example:
Name: C:\, IsOpticalDrive: False
*/

VB

Dim drives() As DriveInfo = DriveInfo.GetDrives()
For i = 0 To drives.Length - 1
    Console.WriteLine($"Name: {drives(i).Name}, IsOpticalDrive: {Env.IsDriveOpticalDrive(drives(i))}")
Next

' Example:
' Name: C:\, IsOpticalDrive: False

Go to top

System Environment

a. GetWindowsVersion

This function is available in version 1.9 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The GetWindowsVersion() enables you to get the Windows version that the user is running. Returns a WindowsVersion enumeration.

Warning

Don't forget to import the LeoCorpLibrary.Enumsor LeoCorpLibrary.Core.Enums namespace.

It's in:

LeoCorpLibrary.Env.GetWindowsVersion()

Warning

This method works only if you specify in the Application Manifest, in the compatibility section, that Windows 8, 8.1 and 10/11 are compatible with the software. Else, it will return Windows8.

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- Windows Vista -->
      <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

      <!-- Windows 7 -->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />

      <!-- Windows 8 -->
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />

      <!-- Windows 8.1 -->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />

      <!-- Windows 10 -->
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

    </application>
  </compatibility>

Note

This file is an example. You can create this file by right-clicking on the project, then "Add", "New element", then "Application manifest" and "Add".

Here's an example of usage:

C#

WindowsVersion winver = Env.GetWindowsVersion(); // Get Windows version
/*
Can return:
WindowsVersion.Windows7
WindowsVersion.Windows8
WindowsVersion.Windows81
WindowsVersion.Windows10
WindowsVersion.Windows11 (available in version 4.1+)
/*

VB

Dim winver As WindowsVersion = Env.GetWindowsVersion() ' Get Windows version
' Can return:
' WindowsVersion.Windows7
' WindowsVersion.Windows8
' WindowsVersion.Windows81
' WindowsVersion.Windows10
' WindowsVersion.Windows11 (available in version 4.1+)

Go to top

b. ExecuteAsAdmin

This function is available in version 1.9 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The ExecuteAsAdmin() allows you to execute a program in admin mode on Windows.

It's in:

LeoCorpLibrary.Env.ExecuteAsAdmin()

This method has two variation:

Variation 1

Env.ExecuteAsAdmin(Process process) {...}
ValueArgumentDescription
ProcessprocessProcess with StartInfo.FileName indicated

Variation 2

Env.ExecuteAsAdmin(string filename) {...}
ValueArgumentDescription
stringfilenameThe location of the software to launch in admin mode

Here's an example of usage:

C#

// Variation 1
Process process = new Process();
process.StartInfo.FileName = @"C:\Windows\System32\cmd.exe";
Env.ExecuteAsAdmin(process);

// Variation 2
Env.ExecuteAsAdmin(@"C:\Windows\System32\cmd.exe");

VB

' Variation 1
Dim process As Process = New Process()
process.StartInfo.FileName = "C:/Windows/System32/cmd.exe"
Env.ExecuteAsAdmin(process)

' Variation 2
Env.ExecuteAsAdmin("C:/Windows/System32/cmd.exe")

Go to top

c. GetUnixTime

This function is available in version 2.1 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method allows you to get the current UnixTime or the UnixTime of a specific date/time. Returns an int value.

It's in:

LeoCorpLibrary.Env.GetUnixTime()

It has two variation:

Variation 1

The variation does not accept any arguments.

Variation 2

This variation has an argument:

ValueArgumentDescription
DateTimedateThe specific date to get the UnixTime of

Here's an example of usage:

C#

// Variation 1
int currentUnixTime = Env.GetUnixTime();

// Variation 2
DateTime dateTime = new DateTime(1970, 1, 1);
int unixTime = Env.GetUnixTime(dateTime);

VB

' Variation 1
Dim currentUnixTime As Integer = Env.GetUnixTime()

' Variation 2
Dim dateTime As DateTime = New DateTime(1970, 1, 1)
Dim unixTime As Integer = Env.GetUnixTime(dateTime)

Go to top

d. GetAppDataPath

This function is available in version 2.2 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method allows you to get the user's %APPDATA% path. Returns a string value.

It's in:

LeoCorpLibrary.Env.GetAppDataPath()

It has no arguments.

Here's an example of usage:

C#

string appDataPath = Env.GetAppDataPath();

VB

dim appDataPath As String = Env.GetAppDataPath()

Go to top

e. GetMouseCursorPosition

This function is available in version 3.4 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method allows you to get the current position of the mouse cursor on the screen. It returns a Point value (System.Drawing).

It's in:

LeoCorpLibrary.Env.GetMouseCursorPosition()

It has no arguments.

Note

This method is using Windows Forms features, so use this method in Windows Forms projects only. If your project is using WPF, check GetMouseCursorPositionWPF().

Here's an example of usage:

C#

Point p = Env.GetMouseCursorPosition();
MessageBox.Show($"Mouse position: X = {p.X}; Y = {p.Y}");

VB

Dim p As Point = Env.GetMouseCursorPosition()
MessageBox.Show("Mouse position: X = " + p.X.ToString() + "; Y = " + p.Y.ToString())

Go to top

f. GetMouseCursorPositionWPF

This function is available in version 3.4 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method allows you to get the current position of the mouse cursor on the screen. It returns a Point value (System.Windows).

It's in:

LeoCorpLibrary.Env.GetMouseCursorPositionWPF()

It has no arguments.

Here's an example of usage:

C#

Point p = Env.GetMouseCursorPosition();
MessageBox.Show($"Mouse position: X = {p.X}; Y = {p.Y}");

VB

Dim p As Point = Env.GetMouseCursorPosition()
MessageBox.Show("Mouse position: X = " + p.X.ToString() + "; Y = " + p.Y.ToString())

Go to top

g. UnixTimeToDateTime

This function is available in version 3.4 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method allows you to convert UnixTime (int) to a DateTime object. Returns a DateTime value.

It's in:

LeoCorpLibrary.Env.UnixTimeToDateTime()

It has one argument:

ValueArgumentDescription
intunixTimeThe UnixTime to convert

Here's an example of usage:

C#

int unixTime = 1615538407;
DateTime date = Env.UnixTimeToDateTime(unixTime); // 12/03/2021 @ 09:40:07

VB

Dim unixTime As Integer = 1615538407
Dim date As DateTime = Env.UnixTimeToDateTime(unixTime) ' 12/03/2021 @ 09:40:07

Go to top

h. IsProcessRunning

This function is available in version 3.4 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method allows you to check if a specific process is currently running. Returns a bool value.

It's in:

LeoCorpLibrary.Env.IsProcessRunning()

It has one argument:

ValueArgumentDescription
intprocessNameThe process name to find

Here's an example of usage:

C#

if (IsProcessRunning("cmd.exe"))
{
    MessageBox.Show("You have a command prompt running.")
}

VB

If IsProcessRunning("cmd.exe") Then
    MessageBox.Show("You have a command prompt running.")
End If

Go to top

i. LaunchUWPApp

This function is available in version 3.9 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method allows you to launch an UWP app from its PackageFamilyName and its Application Id. You can find this information by running in Windows Powershell (admin) the following command:

Get-AppxPackage | Select PackageFamilyName, InstallLocation

You can find the Application Id in the AppxManifest.xml file in

InstallLocation\AppxManifest.xml

This method isn't available in LeoCorpLibrary.Core.

It's in:

LeoCorpLibrary.Env.LaunchUWPApp()

It has two arguments:

ValueArgumentDescription
stringpackageFamilyNameThe PackageFamilyName property
stringapplicationIDThe Application Id property in the UWP AppxManifest.xml file

Here's an example of usage:

C#

// Launch Minecraft UWP
Env.LaunchUWPApp("Microsoft.MinecraftUWP_8wekyb3d8bbwe", "App"); // Launch

VB

' Launch Minecraft UWP
Env.LaunchUWPApp("Microsoft.MinecraftUWP_8wekyb3d8bbwe", "App") ' Launch

Go to top

j. DateTimeToUnixTime

This function is available in version 4.8 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

This method allows you to convert a DateTime object to UnixTime (int). Returns an int value.

It's in:

LeoCorpLibrary.Env.DateTimeToUnixTime()

It has one argument:

ValueArgumentDescription
DateTimedateTimeThe DateTime to convert

Here's an example of usage:

C#

DateTime date = DateTime.Now;
int unixTime = Env.DateTimeToUnixTime(date); // Current UnixTime

// unixTime is now the current UnixTime

VB

Dim date As DateTime = DateTime.Now
Dim unixTime As Integer = Env.DateTimeToUnixTime(date) ' Current UnixTime

' unixTime is now the current UnixTime

Go to top

Properties

File System

a. SystemDrive

This property is available in version 3.1 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The SystemDrive property allows you to get the DriveInfo of the system drive.

WARNING

This property only works on Windows!

It's in:

LeoCorpLibrary.Env.SystemDrive

Here's an example of usage:

C#

DriveInfo sysDrive = Env.SystemDrive; // Get system drive

VB

Dim sysDrive As DriveInfo = Env.SystemDrive ' Get system drive

Go to top

b. AppDataPath

This property is available in version 3.1 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The AppDataPath property allows you to get the %APPDATA% directory path.

It's in:

LeoCorpLibrary.Env.AppDataPath

Here's an example of usage:

C#

string appDataPath = Env.AppDataPath; // Get %APPDATA%

VB

Dim appDataPath As String = Env.AppDataPath ' Get %APPDATA%

Go to top

c. CurrentAppDirectory

This property is available in version 4.8 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The CurrentAppDirectory property allows you to get the current directory path of the app. It returns a string value.

It's in:

LeoCorpLibrary.Env.CurrentAppDirectory

Here's an example of usage:

C#

string currentAppDirectory = Env.CurrentAppDirectory; // Get current app directory

VB

Dim currentAppDirectory As String = Env.CurrentAppDirectory ' Get current app directory

Go to top

System Environment

a. CurrentOperatingSystem

This property is available in version 3.1 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The CurrentOperatingSystem property allows you to get the current Operating system. It returns a OperatingSystems enum:

  • Windows
  • macOS
  • Linux
  • Unknown

It's in:

LeoCorpLibrary.Env.CurrentOperatingSystem

Here's an example of usage:

C#

Console.WriteLine($"The current OS is {Env.CurrentOperatingSystem.ToString()}");

VB

Console.WriteLine("The current OS is" + Env.CurrentOperatingSystem.ToString())

Go to top

b. UnixTime

This property is available in version 3.1 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The UnixTime property allows you to get the current Unix time.

It's in:

LeoCorpLibrary.Env.UnixTime

Here's an example of usage:

C#

while (true)
{
    Console.WriteLine(Env.UnixTime.ToString());
    Thread.Sleep(1000);
}

VB

While True
    Console.WriteLine(Env.UnixTime.ToString())
    Thread.Sleep(1000)
End While

Go to top

c. SystemTheme

This property is available in version 4.2 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The SystemTheme property allows you to get the current SystemThemes of the operating system. Works only on Windows. It returns a SystemThemes enum.

It's in:

LeoCorpLibrary.Env.SystemTheme

Here's an example of usage:

C#

// Running on Windows 11, with dark theme enabled.

Console.WriteLine(Env.SystemTheme.ToString());
// Output:
// Dark

VB

' Running on Windows 11, with dark theme enabled.

Console.WriteLine(Env.SystemTheme.ToString())
' Output:
' Dark

Go to top

d. IsDarkThemeAvailable

This property is available in version 4.2 and higher.

Compatibility
FrameworksLeoCorpLibraryLeoCorpLibrary.Core
.NET 6
.NET 5
.NET Core 3.1
.NET Framework 4.5

The IsDarkThemeAvailable property allows you to get if dark theme is supported on the current operating system. It returns a bool value.

It's in:

LeoCorpLibrary.Env.IsDarkThemeAvailable

Here's an example of usage:

C#

// Running on Windows 7
Console.WriteLine(Env.IsDarkThemeAvailable.ToString());

// Output:
// False

VB

' Running on Windows 7
Console.WriteLine(Env.IsDarkThemeAvailable.ToString())

' Output:
' False

Go to top