mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
namespace LanMountainDesktop.PluginMarketplace;
|
|
|
|
internal sealed class AirAppMarketCacheService
|
|
{
|
|
private readonly string _cacheDirectory;
|
|
|
|
public AirAppMarketCacheService(string dataDirectory)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(dataDirectory);
|
|
_cacheDirectory = Path.Combine(dataDirectory, "cache");
|
|
}
|
|
|
|
public string CacheFilePath => Path.Combine(_cacheDirectory, "index.json");
|
|
|
|
public void SaveIndexJson(string json)
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(json);
|
|
Directory.CreateDirectory(_cacheDirectory);
|
|
File.WriteAllText(CacheFilePath, json);
|
|
}
|
|
|
|
public bool TryReadIndexJson(out string json)
|
|
{
|
|
try
|
|
{
|
|
if (!File.Exists(CacheFilePath))
|
|
{
|
|
json = string.Empty;
|
|
return false;
|
|
}
|
|
|
|
json = File.ReadAllText(CacheFilePath);
|
|
return !string.IsNullOrWhiteSpace(json);
|
|
}
|
|
catch
|
|
{
|
|
json = string.Empty;
|
|
return false;
|
|
}
|
|
}
|
|
}
|