Files
@ e7cc8ddcbf58
Branch filter:
Location: ATITD-Tools/Desert-Paint-Codex/Services/ProfileManager.cs - annotation
e7cc8ddcbf58
2.7 KiB
text/x-csharp
Update version number to 1.4.0.0
40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 a5faa82faf6a a5faa82faf6a a5faa82faf6a a5faa82faf6a a5faa82faf6a a5faa82faf6a 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 40eaee10ae56 |
using System;
using DesertPaintCodex.Models;
using DesertPaintCodex.Util;
using System.Collections.Generic;
using System.IO;
namespace DesertPaintCodex.Services
{
internal static class ProfileManager
{
private static bool _areProfilesLoaded;
private static readonly List<string> _profileList = new();
public static PlayerProfile? CurrentProfile { get; private set; }
public static bool HasProfileLoaded => CurrentProfile != null;
public static List<string> GetProfileList()
{
// If it's already loaded, return the cached list.
if (_areProfilesLoaded)
{
return _profileList;
}
// Otherwise, load the list.
string appDataPath = FileUtils.AppDataPath;
if (!Directory.Exists(appDataPath))
{
Directory.CreateDirectory(appDataPath);
}
DirectoryInfo di = new(appDataPath);
DirectoryInfo[] dirs = di.GetDirectories();
foreach (DirectoryInfo dir in dirs)
{
if (dir.Name != "template")
{
_profileList.Add(dir.Name);
}
}
_areProfilesLoaded = true;
return _profileList;
}
public static PlayerProfile LoadProfile(string name)
{
CurrentProfile = new PlayerProfile(name, Path.Combine(FileUtils.AppDataPath, name));
CurrentProfile.Load();
return CurrentProfile;
}
public static void ReloadProfile()
{
if (CurrentProfile == null) return;
LoadProfile(CurrentProfile.Name);
}
public static PlayerProfile CreateNewProfile(string name)
{
CurrentProfile = new PlayerProfile(name, Path.Combine(FileUtils.AppDataPath, name));
CurrentProfile.Initialize();
// Invalidate profile list, so it will reload next time.
_profileList.Clear();
_areProfilesLoaded = false;
return CurrentProfile;
}
public static int GetProfileCount()
{
// This is a function instead of a property, because it may be slow.
List<string> profiles = GetProfileList();
return profiles.Count;
}
public static bool HasProfiles()
{
// This is a function instead of a property, because it may be slow.
List<string> profiles = GetProfileList();
return profiles.Count > 0;
}
public static void UnloadProfile()
{
CurrentProfile = null;
}
}
}
|