mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-01 20:34:57 +01:00
698 lines did all of it at once. The mutable CaptureFromUi callback becomes an ISettingsCapture the settings view implements.
36 lines
1.1 KiB
C#
36 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using StarterNG.Application;
|
|
|
|
namespace StarterNG.Classes;
|
|
|
|
public static class SettingsProfileStore
|
|
{
|
|
public static string DirectoryPath { get; } =
|
|
Path.Combine(AppServices.Current.SettingsPaths.UserConfigDirectory(), "starter", "profiles");
|
|
|
|
public static IReadOnlyList<string> ListProfiles()
|
|
{
|
|
try
|
|
{
|
|
if (!Directory.Exists(DirectoryPath)) return Array.Empty<string>();
|
|
return Directory.GetFiles(DirectoryPath, "*.ini")
|
|
.Select(Path.GetFileNameWithoutExtension)
|
|
.Where(n => !string.IsNullOrEmpty(n))
|
|
.OrderBy(n => n, StringComparer.OrdinalIgnoreCase)
|
|
.ToList()!;
|
|
}
|
|
catch { return Array.Empty<string>(); }
|
|
}
|
|
|
|
public static string PathFor(string name)
|
|
{
|
|
string safe = name.Trim();
|
|
foreach (char c in Path.GetInvalidFileNameChars())
|
|
safe = safe.Replace(c, '_');
|
|
return Path.Combine(DirectoryPath, safe + ".ini");
|
|
}
|
|
}
|