DesktopStorageService.cs 1.0 KB

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