mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
remove filesystem context
This commit is contained in:
@@ -1,174 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Context.FileSystem.Location;
|
||||
using System.IO;
|
||||
|
||||
namespace Snap.Hutao.Context.FileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// 文件系统上下文
|
||||
/// </summary>
|
||||
/// <typeparam name="TLocation">路径位置类型</typeparam>
|
||||
internal abstract class FileSystemContext
|
||||
{
|
||||
private readonly IFileSystemLocation location;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化文件系统上下文
|
||||
/// </summary>
|
||||
/// <param name="location">指定的文件系统位置</param>
|
||||
public FileSystemContext(IFileSystemLocation location)
|
||||
{
|
||||
this.location = location;
|
||||
EnsureDirectory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建文件,若已存在文件,则不会创建
|
||||
/// </summary>
|
||||
/// <param name="file">文件</param>
|
||||
public void CreateFileOrIgnore(string file)
|
||||
{
|
||||
file = Locate(file);
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
File.Create(file).Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建文件夹,若已存在文件,则不会创建
|
||||
/// </summary>
|
||||
/// <param name="folder">文件夹</param>
|
||||
public void CreateFolderOrIgnore(string folder)
|
||||
{
|
||||
folder = Locate(folder);
|
||||
if (!Directory.Exists(folder))
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试删除文件夹
|
||||
/// </summary>
|
||||
/// <param name="folder">文件夹</param>
|
||||
public void DeleteFolderOrIgnore(string folder)
|
||||
{
|
||||
folder = Locate(folder);
|
||||
if (Directory.Exists(folder))
|
||||
{
|
||||
Directory.Delete(folder, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查文件是否存在
|
||||
/// </summary>
|
||||
/// <param name="file">文件名称</param>
|
||||
/// <returns>是否存在</returns>
|
||||
public bool FileExists(string file)
|
||||
{
|
||||
return File.Exists(Locate(file));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查文件是否存在
|
||||
/// </summary>
|
||||
/// <param name="folder">文件夹名称</param>
|
||||
/// <param name="file">文件名称</param>
|
||||
/// <returns>是否存在</returns>
|
||||
public bool FileExists(string folder, string file)
|
||||
{
|
||||
return File.Exists(Locate(folder, file));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查文件是否存在
|
||||
/// </summary>
|
||||
/// <param name="folder">文件夹名称</param>
|
||||
/// <returns>是否存在</returns>
|
||||
public bool FolderExists(string folder)
|
||||
{
|
||||
return Directory.Exists(Locate(folder));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定位根目录中的文件或文件夹
|
||||
/// </summary>
|
||||
/// <param name="fileOrFolder">文件或文件夹</param>
|
||||
/// <returns>绝对路径</returns>
|
||||
public string Locate(string fileOrFolder)
|
||||
{
|
||||
return Path.GetFullPath(fileOrFolder, location.GetPath());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定位根目录下子文件夹中的文件
|
||||
/// </summary>
|
||||
/// <param name="folder">文件夹</param>
|
||||
/// <param name="file">文件</param>
|
||||
/// <returns>绝对路径</returns>
|
||||
public string Locate(string folder, string file)
|
||||
{
|
||||
return Path.GetFullPath(Path.Combine(folder, file), location.GetPath());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将文件移动到指定的子目录
|
||||
/// </summary>
|
||||
/// <param name="file">文件</param>
|
||||
/// <param name="folder">文件夹</param>
|
||||
/// <param name="overwrite">是否覆盖</param>
|
||||
/// <returns>是否成功 当文件不存在时会失败</returns>
|
||||
public bool MoveToFolderOrIgnore(string file, string folder, bool overwrite = true)
|
||||
{
|
||||
string target = Locate(folder, file);
|
||||
file = Locate(file);
|
||||
|
||||
if (File.Exists(file))
|
||||
{
|
||||
File.Move(file, target, overwrite);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等效于 <see cref="File.OpenRead(string)"/> ,但路径经过解析
|
||||
/// </summary>
|
||||
/// <param name="file">文件名</param>
|
||||
/// <returns>文件流</returns>
|
||||
public FileStream OpenRead(string file)
|
||||
{
|
||||
return File.OpenRead(Locate(file));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 等效于 <see cref="File.Create(string)"/> ,但路径经过解析
|
||||
/// </summary>
|
||||
/// <param name="file">文件名</param>
|
||||
/// <returns>文件流</returns>
|
||||
public FileStream Create(string file)
|
||||
{
|
||||
return File.Create(Locate(file));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查根目录
|
||||
/// </summary>
|
||||
/// <returns>是否创建了路径</returns>
|
||||
private bool EnsureDirectory()
|
||||
{
|
||||
string folder = location.GetPath();
|
||||
if (!Directory.Exists(folder))
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Context.FileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// 我的文档上下文
|
||||
/// </summary>
|
||||
[Injection(InjectAs.Transient)]
|
||||
internal class HutaoContext : FileSystemContext
|
||||
{
|
||||
/// <inheritdoc cref="FileSystemContext"/>
|
||||
public HutaoContext(Location.HutaoLocation myDocument)
|
||||
: base(myDocument)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.IO;
|
||||
using Windows.ApplicationModel;
|
||||
|
||||
namespace Snap.Hutao.Context.FileSystem.Location;
|
||||
|
||||
/// <summary>
|
||||
/// 我的文档位置
|
||||
/// </summary>
|
||||
[Injection(InjectAs.Transient)]
|
||||
internal class HutaoLocation : IFileSystemLocation
|
||||
{
|
||||
private string? path;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string GetPath()
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
string myDocument = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
#if RELEASE
|
||||
// 将测试版与正式版的文件目录分离
|
||||
string folderName = Package.Current.PublisherDisplayName == "DGP Studio CI" ? "HutaoAlpha" : "Hutao";
|
||||
#else
|
||||
// 使得迁移能正常生成
|
||||
string folderName = "Hutao";
|
||||
#endif
|
||||
path = Path.GetFullPath(Path.Combine(myDocument, folderName));
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Snap.Hutao.Context.FileSystem.Location;
|
||||
|
||||
/// <summary>
|
||||
/// 文件系统位置
|
||||
/// </summary>
|
||||
public interface IFileSystemLocation
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取路径
|
||||
/// </summary>
|
||||
/// <returns>路径</returns>
|
||||
string GetPath();
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace Snap.Hutao.Context.FileSystem.Location;
|
||||
|
||||
/// <summary>
|
||||
/// 我的文档位置
|
||||
/// </summary>
|
||||
[Injection(InjectAs.Transient)]
|
||||
internal class Metadata : IFileSystemLocation
|
||||
{
|
||||
private string? path;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string GetPath()
|
||||
{
|
||||
if (string.IsNullOrEmpty(path))
|
||||
{
|
||||
string myDocument = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
path = Path.GetFullPath(Path.Combine(myDocument, "Hutao", "Metadata"));
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Context.FileSystem.Location;
|
||||
|
||||
namespace Snap.Hutao.Context.FileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// 元数据上下文
|
||||
/// </summary>
|
||||
[Injection(InjectAs.Transient)]
|
||||
internal class MetadataContext : FileSystemContext
|
||||
{
|
||||
/// <inheritdoc cref="FileSystemContext"/>
|
||||
public MetadataContext(Metadata metadata)
|
||||
: base(metadata)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Snap.Hutao.Core.Caching;
|
||||
using Snap.Hutao.Extension;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace Snap.Hutao.Control.Image;
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ using Snap.Hutao.Service.Abstraction;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Streams;
|
||||
|
||||
namespace Snap.Hutao.Control.Image;
|
||||
|
||||
|
||||
@@ -6,9 +6,7 @@ using Microsoft.UI.Composition;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using System.IO;
|
||||
using System.Numerics;
|
||||
using Windows.Graphics.Imaging;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.Streams;
|
||||
|
||||
namespace Snap.Hutao.Control.Image;
|
||||
@@ -28,8 +26,8 @@ public class Gradient : CompositionImage
|
||||
/// </summary>
|
||||
public GradientDirection BackgroundDirection
|
||||
{
|
||||
get { return (GradientDirection)GetValue(BackgroundDirectionProperty); }
|
||||
set { SetValue(BackgroundDirectionProperty, value); }
|
||||
get => (GradientDirection)GetValue(BackgroundDirectionProperty);
|
||||
set => SetValue(BackgroundDirectionProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,8 +35,8 @@ public class Gradient : CompositionImage
|
||||
/// </summary>
|
||||
public GradientDirection ForegroundDirection
|
||||
{
|
||||
get { return (GradientDirection)GetValue(ForegroundDirectionProperty); }
|
||||
set { SetValue(ForegroundDirectionProperty, value); }
|
||||
get => (GradientDirection)GetValue(ForegroundDirectionProperty);
|
||||
set => SetValue(ForegroundDirectionProperty, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Windows.Storage;
|
||||
|
||||
namespace Snap.Hutao.Core.Caching;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,6 +7,7 @@ using Snap.Hutao.Core.Json;
|
||||
using Snap.Hutao.Extension;
|
||||
using Snap.Hutao.Web.Hoyolab.DynamicSecret;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Text.Json.Serialization.Metadata;
|
||||
using Windows.ApplicationModel;
|
||||
|
||||
@@ -70,6 +71,11 @@ internal static class CoreEnvironment
|
||||
/// </summary>
|
||||
public static readonly string FamilyName;
|
||||
|
||||
/// <summary>
|
||||
/// 数据文件夹
|
||||
/// </summary>
|
||||
public static readonly string DataFolder;
|
||||
|
||||
/// <summary>
|
||||
/// 默认的Json序列化选项
|
||||
/// </summary>
|
||||
@@ -93,6 +99,7 @@ internal static class CoreEnvironment
|
||||
|
||||
static CoreEnvironment()
|
||||
{
|
||||
DataFolder = GetDocumentsHutaoPath();
|
||||
Version = Package.Current.Id.Version.ToVersion();
|
||||
FamilyName = Package.Current.Id.FamilyName;
|
||||
CommonUA = $"Snap Hutao/{Version}";
|
||||
@@ -108,4 +115,19 @@ internal static class CoreEnvironment
|
||||
object? machineGuid = Registry.GetValue(CryptographyKey, MachineGuidValue, userName);
|
||||
return Md5Convert.ToHexString($"{userName}{machineGuid}");
|
||||
}
|
||||
|
||||
private static string GetDocumentsHutaoPath()
|
||||
{
|
||||
string myDocument = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
|
||||
#if RELEASE
|
||||
// 将测试版与正式版的文件目录分离
|
||||
string folderName = Package.Current.PublisherDisplayName == "DGP Studio CI" ? "HutaoAlpha" : "Hutao";
|
||||
#else
|
||||
// 使得迁移能正常生成
|
||||
string folderName = "Hutao";
|
||||
#endif
|
||||
string path = Path.GetFullPath(Path.Combine(myDocument, folderName));
|
||||
Directory.CreateDirectory(path);
|
||||
return path;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Snap.Hutao.Context.FileSystem;
|
||||
using Snap.Hutao.Model.Entity.Database;
|
||||
using System.Diagnostics;
|
||||
|
||||
@@ -31,9 +30,7 @@ internal static class IocConfiguration
|
||||
/// <returns>可继续操作的集合</returns>
|
||||
public static IServiceCollection AddDatebase(this IServiceCollection services)
|
||||
{
|
||||
HutaoContext myDocument = new(new());
|
||||
|
||||
string dbFile = myDocument.Locate("Userdata.db");
|
||||
string dbFile = System.IO.Path.Combine(CoreEnvironment.DataFolder, "Userdata.db");
|
||||
string sqlConnectionString = $"Data Source={dbFile}";
|
||||
|
||||
// temporarily create a context
|
||||
|
||||
@@ -2,11 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Snap.Hutao.Core.IO;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.Networking.BackgroundIntelligentTransferService;
|
||||
|
||||
namespace Snap.Hutao.Core.IO.Bits;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Snap.Hutao.Context.FileSystem;
|
||||
using Snap.Hutao.Model.Entity.Database;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Diagnostics;
|
||||
@@ -61,8 +60,8 @@ public sealed class LogEntryQueue : IDisposable
|
||||
|
||||
private static LogDbContext InitializeDbContext()
|
||||
{
|
||||
HutaoContext myDocument = new(new());
|
||||
LogDbContext logDbContext = LogDbContext.Create($"Data Source={myDocument.Locate("Log.db")}");
|
||||
string logDbName = System.IO.Path.Combine(CoreEnvironment.DataFolder, "Log.db");
|
||||
LogDbContext logDbContext = LogDbContext.Create($"Data Source={logDbName}");
|
||||
if (logDbContext.Database.GetPendingMigrations().Any())
|
||||
{
|
||||
Debug.WriteLine("[Debug] Performing LogDbContext Migrations");
|
||||
@@ -70,7 +69,7 @@ public sealed class LogEntryQueue : IDisposable
|
||||
}
|
||||
|
||||
// only raw sql can pass
|
||||
logDbContext.Database.ExecuteSqlRaw("DELETE FROM logs WHERE Exception IS NULL");
|
||||
logDbContext.Logs.Where(log => log.Exception == null).ExecuteDelete();
|
||||
return logDbContext;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Model.Entity.Configuration;
|
||||
|
||||
namespace Snap.Hutao.Model.Entity.Database;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Snap.Hutao.Context.FileSystem;
|
||||
using Snap.Hutao.Model.Entity.Database;
|
||||
|
||||
namespace Snap.Hutao.Context.Database;
|
||||
@@ -17,7 +16,7 @@ public class AppDbContextDesignTimeFactory : IDesignTimeDbContextFactory<AppDbCo
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public AppDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
HutaoContext myDocument = new(new());
|
||||
return AppDbContext.Create($"Data Source={myDocument.Locate("Userdata.db")}");
|
||||
string userdataDbName = System.IO.Path.Combine(Core.CoreEnvironment.DataFolder, "Userdata.db");
|
||||
return AppDbContext.Create($"Data Source={userdataDbName}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
using Snap.Hutao.Context.FileSystem;
|
||||
using Snap.Hutao.Model.Entity.Database;
|
||||
|
||||
namespace Snap.Hutao.Context.Database;
|
||||
@@ -17,7 +16,7 @@ public class LogDbContextDesignTimeFactory : IDesignTimeDbContextFactory<LogDbCo
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public LogDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
HutaoContext myDocument = new(new());
|
||||
return LogDbContext.Create($"Data Source={myDocument.Locate("Log.db")}");
|
||||
string logDbName = System.IO.Path.Combine(Core.CoreEnvironment.DataFolder, "Log.db");
|
||||
return LogDbContext.Create($"Data Source={logDbName}");
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Snap.Hutao.Extension;
|
||||
using Snap.Hutao.Model;
|
||||
using Snap.Hutao.Model.Binding.AvatarProperty;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Metadata.Annotation;
|
||||
using Snap.Hutao.Model.Metadata.Avatar;
|
||||
using Snap.Hutao.Model.Metadata.Converter;
|
||||
using ModelPlayerInfo = Snap.Hutao.Web.Enka.Model.PlayerInfo;
|
||||
|
||||
namespace Snap.Hutao.Service.AvatarInfo.Factory;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Snap.Hutao.Context.FileSystem;
|
||||
using Snap.Hutao.Core.Abstraction;
|
||||
using Snap.Hutao.Core.DependencyInjection.Annotation.HttpClient;
|
||||
using Snap.Hutao.Core.Diagnostics;
|
||||
@@ -25,9 +24,9 @@ internal partial class MetadataService : IMetadataService, IMetadataInitializer,
|
||||
{
|
||||
private const string MetaFileName = "Meta.json";
|
||||
|
||||
private readonly string metadataFolderPath;
|
||||
private readonly IInfoBarService infoBarService;
|
||||
private readonly HttpClient httpClient;
|
||||
private readonly FileSystemContext metadataContext;
|
||||
private readonly JsonSerializerOptions options;
|
||||
private readonly ILogger<MetadataService> logger;
|
||||
private readonly IMemoryCache memoryCache;
|
||||
@@ -44,24 +43,24 @@ internal partial class MetadataService : IMetadataService, IMetadataInitializer,
|
||||
/// </summary>
|
||||
/// <param name="infoBarService">信息条服务</param>
|
||||
/// <param name="httpClientFactory">http客户端工厂</param>
|
||||
/// <param name="metadataContext">我的文档上下文</param>
|
||||
/// <param name="options">json序列化选项</param>
|
||||
/// <param name="logger">日志器</param>
|
||||
/// <param name="memoryCache">内存缓存</param>
|
||||
public MetadataService(
|
||||
IInfoBarService infoBarService,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
MetadataContext metadataContext,
|
||||
JsonSerializerOptions options,
|
||||
ILogger<MetadataService> logger,
|
||||
IMemoryCache memoryCache)
|
||||
{
|
||||
this.infoBarService = infoBarService;
|
||||
this.metadataContext = metadataContext;
|
||||
this.options = options;
|
||||
this.logger = logger;
|
||||
this.memoryCache = memoryCache;
|
||||
httpClient = httpClientFactory.CreateClient(nameof(MetadataService));
|
||||
|
||||
metadataFolderPath = Path.Combine(Core.CoreEnvironment.DataFolder, "Metadata");
|
||||
Directory.CreateDirectory(metadataFolderPath);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
@@ -111,7 +110,7 @@ internal partial class MetadataService : IMetadataService, IMetadataInitializer,
|
||||
await CheckMetadataAsync(metaMd5Map, token).ConfigureAwait(false);
|
||||
|
||||
// save metadataFile
|
||||
using (FileStream metaFileStream = metadataContext.Create(MetaFileName))
|
||||
using (FileStream metaFileStream = File.Create(Path.Combine(metadataFolderPath, MetaFileName)))
|
||||
{
|
||||
await JsonSerializer
|
||||
.SerializeAsync(metaFileStream, metaMd5Map, options, token)
|
||||
@@ -136,7 +135,7 @@ internal partial class MetadataService : IMetadataService, IMetadataInitializer,
|
||||
string fileFullName = $"{fileName}.json";
|
||||
|
||||
bool skip = false;
|
||||
if (metadataContext.FileExists(fileFullName))
|
||||
if (File.Exists(Path.Combine(metadataFolderPath, fileFullName)))
|
||||
{
|
||||
skip = md5 == await GetFileMd5Async(fileFullName, token).ConfigureAwait(false);
|
||||
}
|
||||
@@ -152,7 +151,7 @@ internal partial class MetadataService : IMetadataService, IMetadataInitializer,
|
||||
|
||||
private async Task<string> GetFileMd5Async(string fileFullName, CancellationToken token)
|
||||
{
|
||||
using (FileStream stream = metadataContext.OpenRead(fileFullName))
|
||||
using (FileStream stream = File.OpenRead(Path.Combine(metadataFolderPath, fileFullName)))
|
||||
{
|
||||
byte[] bytes = await MD5.Create()
|
||||
.ComputeHashAsync(stream, token)
|
||||
@@ -171,7 +170,7 @@ internal partial class MetadataService : IMetadataService, IMetadataInitializer,
|
||||
// Write stream while convert LF to CRLF
|
||||
using (StreamReader streamReader = new(sourceStream))
|
||||
{
|
||||
using (StreamWriter streamWriter = new(metadataContext.Create(fileFullName)))
|
||||
using (StreamWriter streamWriter = new(File.Create(Path.Combine(metadataFolderPath, fileFullName))))
|
||||
{
|
||||
while (await streamReader.ReadLineAsync(token).ConfigureAwait(false) is string line)
|
||||
{
|
||||
@@ -195,7 +194,7 @@ internal partial class MetadataService : IMetadataService, IMetadataInitializer,
|
||||
return Must.NotNull((T)value!);
|
||||
}
|
||||
|
||||
using (Stream fileStream = metadataContext.OpenRead($"{fileName}.json"))
|
||||
using (Stream fileStream = File.OpenRead(Path.Combine(metadataFolderPath, $"{fileName}.json")))
|
||||
{
|
||||
T? result = await JsonSerializer.DeserializeAsync<T>(fileStream, options, token).ConfigureAwait(false);
|
||||
return memoryCache.Set(cacheKey, Must.NotNull(result!));
|
||||
|
||||
@@ -163,11 +163,11 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.4.27">
|
||||
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.5.10-alpha">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="17.0.64" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Validation" Version="17.0.65" />
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.2.138-beta">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.UI.Converters;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
namespace Snap.Hutao.View.Converter;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.UI.Converters;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
namespace Snap.Hutao.View.Converter;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.UI.Converters;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
namespace Snap.Hutao.View.Converter;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.UI.Converters;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
namespace Snap.Hutao.View.Converter;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.UI.Converters;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) DGP Studio. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.WinUI.UI.Converters;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
|
||||
@@ -5,13 +5,9 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Snap.Hutao.Context.FileSystem.Location;
|
||||
using Snap.Hutao.Factory.Abstraction;
|
||||
using Snap.Hutao.Model.Entity.Database;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
using Snap.Hutao.Service.User;
|
||||
using Snap.Hutao.Web.Hutao;
|
||||
using Snap.Hutao.Web.Hutao.Model.Post;
|
||||
using Windows.Storage;
|
||||
using Windows.System;
|
||||
|
||||
@@ -23,19 +19,12 @@ namespace Snap.Hutao.ViewModel;
|
||||
[Injection(InjectAs.Scoped)]
|
||||
internal class ExperimentalFeaturesViewModel : ObservableObject
|
||||
{
|
||||
private readonly IFileSystemLocation hutaoLocation;
|
||||
|
||||
/// <summary>
|
||||
/// 构造一个新的实验性功能视图模型
|
||||
/// </summary>
|
||||
/// <param name="asyncRelayCommandFactory">异步命令工厂</param>
|
||||
/// <param name="hutaoLocation">数据文件夹</param>
|
||||
public ExperimentalFeaturesViewModel(
|
||||
IAsyncRelayCommandFactory asyncRelayCommandFactory,
|
||||
HutaoLocation hutaoLocation)
|
||||
public ExperimentalFeaturesViewModel(IAsyncRelayCommandFactory asyncRelayCommandFactory)
|
||||
{
|
||||
this.hutaoLocation = hutaoLocation;
|
||||
|
||||
OpenCacheFolderCommand = asyncRelayCommandFactory.Create(OpenCacheFolderAsync);
|
||||
OpenDataFolderCommand = asyncRelayCommandFactory.Create(OpenDataFolderAsync);
|
||||
DeleteUsersCommand = asyncRelayCommandFactory.Create(DangerousDeleteUsersAsync);
|
||||
@@ -69,7 +58,7 @@ internal class ExperimentalFeaturesViewModel : ObservableObject
|
||||
|
||||
private Task OpenDataFolderAsync()
|
||||
{
|
||||
return Launcher.LaunchFolderPathAsync(hutaoLocation.GetPath()).AsTask();
|
||||
return Launcher.LaunchFolderPathAsync(Core.CoreEnvironment.DataFolder).AsTask();
|
||||
}
|
||||
|
||||
private async Task DangerousDeleteUsersAsync()
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Snap.Hutao.Core.Database;
|
||||
using Snap.Hutao.Core.Windowing;
|
||||
using Snap.Hutao.Factory.Abstraction;
|
||||
@@ -14,11 +13,7 @@ using Snap.Hutao.Model.Entity.Database;
|
||||
using Snap.Hutao.Service.GachaLog;
|
||||
using Snap.Hutao.Service.Game;
|
||||
using Snap.Hutao.Service.Game.Locator;
|
||||
using Snap.Hutao.Service.User;
|
||||
using Snap.Hutao.View.Dialog;
|
||||
using Snap.Hutao.Web.Hoyolab;
|
||||
using Snap.Hutao.Web.Hoyolab.Passport;
|
||||
using Snap.Hutao.Web.Response;
|
||||
using System.IO;
|
||||
|
||||
namespace Snap.Hutao.ViewModel;
|
||||
|
||||
@@ -2,37 +2,22 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using CommunityToolkit.WinUI.UI;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Snap.Hutao.Control;
|
||||
using Snap.Hutao.Extension;
|
||||
using Snap.Hutao.Factory.Abstraction;
|
||||
using Snap.Hutao.Message;
|
||||
using Snap.Hutao.Model.Binding.Cultivation;
|
||||
using Snap.Hutao.Model.Binding.Hutao;
|
||||
using Snap.Hutao.Model.Binding.SpiralAbyss;
|
||||
using Snap.Hutao.Model.Binding.User;
|
||||
using Snap.Hutao.Model.Entity;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Metadata;
|
||||
using Snap.Hutao.Model.Metadata.Weapon;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
using Snap.Hutao.Service.Cultivation;
|
||||
using Snap.Hutao.Service.Hutao;
|
||||
using Snap.Hutao.Service.Metadata;
|
||||
using Snap.Hutao.Service.SpiralAbyss;
|
||||
using Snap.Hutao.Service.User;
|
||||
using Snap.Hutao.View.Dialog;
|
||||
using Snap.Hutao.Web.Hutao;
|
||||
using Snap.Hutao.Web.Hutao.Model.Post;
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.ObjectModel;
|
||||
using CalcAvatarPromotionDelta = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.AvatarPromotionDelta;
|
||||
using CalcClient = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.CalculateClient;
|
||||
using CalcConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Consumption;
|
||||
|
||||
namespace Snap.Hutao.ViewModel;
|
||||
|
||||
|
||||
@@ -2,33 +2,17 @@
|
||||
// Licensed under the MIT license.
|
||||
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.WinUI.UI;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Snap.Hutao.Control;
|
||||
using Snap.Hutao.Core.IO;
|
||||
using Snap.Hutao.Core.IO.Bits;
|
||||
using Snap.Hutao.Extension;
|
||||
using Snap.Hutao.Factory.Abstraction;
|
||||
using Snap.Hutao.Model.Binding.Cultivation;
|
||||
using Snap.Hutao.Model.Binding.Hutao;
|
||||
using Snap.Hutao.Model.Intrinsic;
|
||||
using Snap.Hutao.Model.Metadata.Weapon;
|
||||
using Snap.Hutao.Model.Primitive;
|
||||
using Snap.Hutao.Service.Abstraction;
|
||||
using Snap.Hutao.Service.Cultivation;
|
||||
using Snap.Hutao.Service.Hutao;
|
||||
using Snap.Hutao.Service.Metadata;
|
||||
using Snap.Hutao.Service.User;
|
||||
using Snap.Hutao.View.Dialog;
|
||||
using Snap.Hutao.Web.Hoyolab;
|
||||
using Snap.Hutao.Web.Hoyolab.Passport;
|
||||
using Snap.Hutao.Web.Response;
|
||||
using System.Collections.Immutable;
|
||||
using CalcAvatarPromotionDelta = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.AvatarPromotionDelta;
|
||||
using CalcClient = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.CalculateClient;
|
||||
using CalcConsumption = Snap.Hutao.Web.Hoyolab.Takumi.Event.Calculate.Consumption;
|
||||
|
||||
namespace Snap.Hutao.ViewModel;
|
||||
|
||||
|
||||
@@ -371,7 +371,7 @@ public class MiHoYoJSInterface
|
||||
|
||||
if (result != null && param.Callback != null)
|
||||
{
|
||||
await ExecuteCallbackScriptAsync(param.Callback, result.ToString(options)).ConfigureAwait(false);
|
||||
await ExecuteCallbackScriptAsync(param.Callback, result.ToString()).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
using Snap.Hutao.Core.Convert;
|
||||
using Snap.Hutao.Web.Request;
|
||||
using System.Collections.Immutable;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user