new_version_init

This commit is contained in:
2024-02-13 02:59:40 +01:00
Unverified
parent e36c1404ee
commit 91f9b645bd
352 changed files with 6777 additions and 8326 deletions

View File

@@ -0,0 +1,30 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.Services.Authentication
{
public class AuthenticationConfiguration
{
#region PROPERTIES
public string FilePath { get; private set; }
#endregion
#region CONSTRUCTORS
public AuthenticationConfiguration(IConfiguration configuration)
{
IConfigurationSection section = configuration.GetSection("authentication");
FilePath = section["file_path"];
}
#endregion
}
}

View File

@@ -0,0 +1,30 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.Services.Authentication
{
public class AuthenticationData
{
#region PROPERTY
[JsonProperty("twitch")]
public AuthenticationDataTwitch Twitch { get; internal set; }
#endregion
#region CONSTRUCTORS
public AuthenticationData()
{
Twitch = new AuthenticationDataTwitch();
}
#endregion
}
}

View File

@@ -0,0 +1,15 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VDownload.Services.Authentication
{
public class AuthenticationDataTwitch
{
[JsonProperty("token")]
public byte[]? Token { get; set; }
}
}

View File

@@ -0,0 +1,97 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Extensions;
namespace VDownload.Services.Authentication
{
public interface IAuthenticationService
{
#region PROPERTIES
AuthenticationData? AuthenticationData { get; }
#endregion
#region METHODS
Task Load();
Task Save();
#endregion
}
public class AuthenticationService : IAuthenticationService
{
#region SERVICES
private AuthenticationConfiguration _configuration;
#endregion
#region FIELDS
private string _authenticationDataFile;
#endregion
#region PROPERTIES
public AuthenticationData AuthenticationData { get; private set; }
public bool AuthenticationDataLoaded => AuthenticationData is not null;
#endregion
#region CONSTRUCTORS
public AuthenticationService(AuthenticationConfiguration configuration)
{
_configuration = configuration;
_authenticationDataFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), _configuration.FilePath);
}
#endregion
#region PUBLIC METHODS
public async Task Load()
{
AuthenticationData = null;
if (File.Exists(_authenticationDataFile))
{
string content = await File.ReadAllTextAsync(_authenticationDataFile);
AuthenticationData = JsonConvert.DeserializeObject<AuthenticationData>(content);
}
AuthenticationData ??= new AuthenticationData();
}
public async Task Save()
{
Directory.CreateDirectory(Path.GetDirectoryName(_authenticationDataFile));
string content = JsonConvert.SerializeObject(AuthenticationData);
await File.WriteAllTextAsync(_authenticationDataFile, content);
}
#endregion
}
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VDownload.Extensions\VDownload.Extensions.csproj" />
</ItemGroup>
</Project>