32 lines
1.0 KiB
C#
32 lines
1.0 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Windows.Storage;
|
|
using Windows.Storage.Streams;
|
|
|
|
namespace Wino.Helpers
|
|
{
|
|
// Use these extension methods to store and retrieve local and roaming app data
|
|
// More details regarding storing and retrieving app data at https://docs.microsoft.com/windows/uwp/app-settings/store-and-retrieve-app-data
|
|
public static class SettingsStorageExtensions
|
|
{
|
|
public static async Task<byte[]> ReadBytesAsync(this StorageFile file)
|
|
{
|
|
if (file != null)
|
|
{
|
|
using (IRandomAccessStream stream = await file.OpenReadAsync())
|
|
{
|
|
using (var reader = new DataReader(stream.GetInputStreamAt(0)))
|
|
{
|
|
await reader.LoadAsync((uint)stream.Size);
|
|
var bytes = new byte[stream.Size];
|
|
reader.ReadBytes(bytes);
|
|
return bytes;
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|