MiJenner.ConfigUtils-FolderManager 0.9.0

dotnet add package MiJenner.ConfigUtils-FolderManager --version 0.9.0
                    
NuGet\Install-Package MiJenner.ConfigUtils-FolderManager -Version 0.9.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MiJenner.ConfigUtils-FolderManager" Version="0.9.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MiJenner.ConfigUtils-FolderManager" Version="0.9.0" />
                    
Directory.Packages.props
<PackageReference Include="MiJenner.ConfigUtils-FolderManager" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MiJenner.ConfigUtils-FolderManager --version 0.9.0
                    
#r "nuget: MiJenner.ConfigUtils-FolderManager, 0.9.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MiJenner.ConfigUtils-FolderManager@0.9.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MiJenner.ConfigUtils-FolderManager&version=0.9.0
                    
Install as a Cake Addin
#tool nuget:?package=MiJenner.ConfigUtils-FolderManager&version=0.9.0
                    
Install as a Cake Tool

MiJenner.ConfigUtils-FolderManager

Desktop Folder Manager in cross platform C# for handling applications storage of user data and user configuration data. The system enables creation of a subfolder structure with .../YourCompany/YourApp/ ... where you can store data and or configuration files. On Windows the path could be:

C:\Users\john\AppData\Roaming\YourCompany\YourApp 

On MacOS the path could be:

/Users/john/.config/YourCompany/YourApp 

Getting Started

Include the namespace:

using MiJenner.ConfigUtils;

Next, use the configuration builder to build a configuration object:

var config = new DesktopFolderManagerConfigBuilder()
    .WithUserDataPolicy(UserDataPolicy.PolicyFileAppDataRoaming)
    .WithUserDataMagic("")
    .WithUserConfigPolicy(UserConfigPolicy.PolicyFileAppDataRoaming)
    .WithUserConfigMagic("")
    .WithCompanyAndAppName("YourCompany", "YourApp")
    .Build();

Policies

UserDataPolicy and UserConfigPolicy choose from the same list of the following four enums / locations (if username is john):

  • PolicyFileAppDataLocal: Windows C:\Users\john\AppData\Local, MacOS: /Users/john/.local/share, Linux: todo
  • PolicyFileAppDataRoaming: Windows C:\Users\john\AppData\Roaming, MacOS: /Users/john/.config, Linux: todo
  • PolicyFileDesktop: Windows C:\Users\john\Desktop, MacOS: /Users/john/Desktop, Linux: todo
  • PolicyFileDocument: Windows C:\Users\john\Documents, MacOS: /Users/john/, Linux: todo

Note: the latter may not be possible due to security settings on Windows.

Next, you will typically create a folderManager instance, based on the just created configuration:

var folderManager = new DesktopFolderManager(config);

And you would use some logic to determine proper folders for users data and for users configuration, which may be the same. And once found, you want to create them (if already existing this will not harm content). For user data this could be something like:

string dataFolder;
if (!folderManager.TryGetDataFolderPath(out dataFolder))
{
    // user data folder path could not be determined. 
    // logic to get out of that situation.
}
else
{
    // try to create user data folder: 
    if (!folderManager.TryCreateUserDataFolder())
    {
        // user configuration folder could not be created. 
        // logic to get out of that situation. 
    }
}

And if it differs for user configuration data you could use:

string configFolder;
if (!folderManager.TryGetConfigFolderPath(outconfigFolder)) 
{
    // configuration folder path could not be determined. 
    // logic to get out of that situation.
}
else
{
    // try to create user configuration folder: 
    if (!folderManager.TryCreateUserConfigFolder())
    {
        // user configuration folder could not be created. 
        // logic to get out of that situation. 
    }
}

Now your strings cs dataFolder and cs configFolder are (hopefully) proper paths to where you want to store user data, sqlite file, json files etc and so on.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.9.0 228 9/9/2023