Find a file
Sam Therapy d67d2b9997
Some checks failed
Public Preview Builds / publish-preview (push) Failing after 7s
idk what all this is but it's a lot
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2024-03-26 17:27:42 +01:00
.forgejo/workflows E 2024-03-25 00:16:59 +01:00
.github idk what all this is but it's a lot 2024-03-26 17:27:42 +01:00
src idk what all this is but it's a lot 2024-03-26 17:27:42 +01:00
.editorconfig refactor: Put FFI in its own project 2023-10-25 15:55:52 +02:00
.gitattributes feat: Initial commit 2023-05-13 20:10:14 +02:00
.gitignore E 2024-03-25 00:16:59 +01:00
GNUmakefile Bump more to .NET 8 2024-01-31 16:49:19 +01:00
icon.png idk what all this is but it's a lot 2024-03-26 17:27:42 +01:00
LICENSE feat: Initial commit 2023-05-13 20:10:14 +02:00
README.md idk what all this is but it's a lot 2024-03-26 17:27:42 +01:00
Xdg.Net.sln refactor: Rewrite everything 2023-10-25 15:55:57 +02:00

Xdg.Directories

A .NET Standard library for the XDG Base Directory Specification and XDG user directories.

GitHub Actions Workflow Status NuGet Version MIT License

Xdg.Net is a small (the .dll is only 11 KB), fast and portable (Completely supports .NET Standard 2.0 and even NativeAOT!) .NET implementation of the XDG Base Directory Specification and XDG user directories for Windows, MacOS and Linux/FreeBSD.

Installation

Use NuGet to install Xdg.Directories.

From the .NET CLI:

dotnet add package Xdg.Directories

or from Visual Studio's package manager:

Install-Package Xdg.Directories

Pre-releases

Preview releases are uploaded to both GitHub packages (need GitHub account to download) and Forgejo packages (no login required).

Usage

Base Directories, C#

using System;
using Xdg.Directories;

// Prints /home/$USER/.local/share
Console.Writeline(BaseDirectory.DataHome);

// Prints /home/$USER/.cache
Console.Writeline(BaseDirectory.CacheHome)

User Directories, F#

open Xdg.Directories

// Prints /home/$USER/Documents
printfn "%s" UserDirectory.DesktopDir

Default Locations

If any of the respective XDG environment are specified, the variable will always be returned. Otherwise, the value depends on the operating system.

Inspiration is taken from the Go implementation for Windows and MacOS directories.

Base Directory
Environment Variable Windows macOS Linux/FreeBSD
XDG_DATA_HOME %LOCALAPPDATA% $HOME/Library/Application Support $HOME/.local/share
XDG_CONFIG_HOME %LOCALAPPDATA% $HOME/Library/Application Support $HOME/.config
XDG_STATE_HOME %LOCALAPPDATA% $HOME/Library/Application Support $HOME/.local/state
XDG_BIN_HOME null null $HOME/.local/bin
XDG_DATA_DIRS %APPDATA%:%PROGRAMDATA% /Library/Application Support /usr/local/share:/usr/share
XDG_CONFIG_DIRS %LOCALAPPDATA% $HOME/Library/Preferences:/Library/Application Support:/Library/Preferences /etc/xdg
XDG_CACHE_HOME %LOCALAPPDATA% $HOME/Library/Application Support $HOME/.config
XDG_RUNTIME_HOME %LOCALAPPDATA% $HOME/Library/Application Support /run/user/$UID
User Directory

User directories on Windows use Known Folders.

Environment Variable Windows macOS Linux/FreeBSD
XDG_DESKTOP_DIR Desktop $HOME/Desktop $HOME/Desktop
XDG_DOWNLOAD_DIR null $HOME/Downloads $HOME/Downloads
XDG_DOCUMENTS_DIR My Documents $HOME/Documents $HOME/Documents
XDG_MUSIC_DIR My Music $HOME/Music $HOME/Music
XDG_PICTURES_DIRS My Pictures $HOME/Pictures $HOME/Pictures
XDG_VIDEOS_DIR My Videos $HOME/Movies $HOME/Videos
XDG_TEMPLATES_DIR Templates $HOME/Templates $HOME/Templates
XDG_PUBLICSHARE_DIR %PUBLIC% $HOME/Public $HOME/Public
Extra Directories
Windows macOS Linux/FreeBSD
Home %USERPROFILE% $HOME $HOME

Native Library (WIP)

View the README here

License

MIT
Icon is made by Emoji One, CC BY-SA 4.0, via Wikimedia Commons