Files
@ 5e28ba3945f7
Branch filter:
Location: ATITD-Tools/Desert-Paint-Codex/Services/ProfileManager.cs - annotation
5e28ba3945f7
2.7 KiB
text/x-csharp
Recipe count is now a ulong instead of an int so it can show values > 2.47 billion. Also, don't allow clearing the recipe list while the recipe generator is running.
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;
}
}
}
|