DesktopStorageService.cs 996 B

12345678910111213141516171819202122232425262728293031323334
  1. using Avalonia;
  2. using System.IO;
  3. using System.Reflection;
  4. using System.Threading.Tasks;
  5. using VeloeAvaloniaKemonoPartyApp.Services;
  6. namespace VeloeAvaloniaKemonoPartyApp.Desktop.Services
  7. {
  8. public class DesktopStorageService : IStorageService
  9. {
  10. private string _cacheFolder;
  11. public DesktopStorageService()
  12. {
  13. _cacheFolder = Directory.GetParent(Assembly.GetEntryAssembly().Location) + "/cache/";
  14. if (!Directory.Exists(_cacheFolder))
  15. Directory.CreateDirectory(_cacheFolder);
  16. }
  17. public async Task<string?> GetCacheFolderAsync()
  18. {
  19. return await Task.FromResult<string?>(_cacheFolder);
  20. }
  21. }
  22. public static class DesktopStorageServiceAppBuilderExtentions
  23. {
  24. public static AppBuilder InitStorageService(this AppBuilder appBuilder)
  25. {
  26. RegisteredServices.StorageService = new DesktopStorageService();
  27. return appBuilder;
  28. }
  29. }
  30. }