mirror of
https://github.com/maker-community/ElectronBot.DotNet.git
synced 2026-10-28 04:28:36 +08:00
添加导入表情文件逻辑
This commit is contained in:
@@ -13,6 +13,8 @@ public class Constants
|
||||
|
||||
public const string EmojisFolder = "EmojisAction";
|
||||
|
||||
public const string EmojisTempFileFolder = "EmojisFileTemp";
|
||||
|
||||
public const string CustomClockTitleConfigKey = "CustomClockTitleConfigKey";
|
||||
|
||||
public const string DefaultCameraNameKey = "DefaultCameraNameKey";
|
||||
|
||||
@@ -593,4 +593,7 @@
|
||||
<data name="ExportEmojis.Text" xml:space="preserve">
|
||||
<value>导出表情文件</value>
|
||||
</data>
|
||||
<data name="ImportEmojisFileBtn.Label" xml:space="preserve">
|
||||
<value>导入表情</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -594,6 +594,9 @@
|
||||
<value>电子动作时间轴</value>
|
||||
</data>
|
||||
<data name="ExportEmojis.Text" xml:space="preserve">
|
||||
<value>导出表情文件</value>
|
||||
<value>导出表情</value>
|
||||
</data>
|
||||
<data name="ImportEmojisFileBtn.Label" xml:space="preserve">
|
||||
<value>导入表情</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -9,7 +9,8 @@ using ElectronBot.BraincasePreview.Controls;
|
||||
using ElectronBot.BraincasePreview.Helpers;
|
||||
using ElectronBot.BraincasePreview.Models;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Services;
|
||||
using Models;
|
||||
using Verdure.ElectronBot.Core.Helpers;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.Storage;
|
||||
|
||||
@@ -49,6 +50,9 @@ public partial class EmojisEditViewModel : ObservableRecipient
|
||||
private readonly ILocalSettingsService _localSettingsService;
|
||||
|
||||
private readonly IEmojisFileService _emojisFileService;
|
||||
|
||||
|
||||
private readonly IntPtr _hwnd = WinRT.Interop.WindowNative.GetWindowHandle(App.MainWindow);
|
||||
public EmojisEditViewModel(IActionExpressionProvider actionExpressionProvider,
|
||||
ILocalSettingsService localSettingsService,
|
||||
IEmojisFileService emojisFileService)
|
||||
@@ -86,6 +90,110 @@ public partial class EmojisEditViewModel : ObservableRecipient
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入表情文件
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
public async Task ImportEmojisFileAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var picker = new Windows.Storage.Pickers.FileOpenPicker
|
||||
{
|
||||
ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
|
||||
|
||||
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Downloads
|
||||
};
|
||||
|
||||
picker.FileTypeFilter.Add(".zip");
|
||||
|
||||
WinRT.Interop.InitializeWithWindow.Initialize(picker, _hwnd);
|
||||
|
||||
var file = await picker.PickSingleFileAsync();
|
||||
|
||||
if (file != null)
|
||||
{
|
||||
var folder = ApplicationData.Current.LocalFolder;
|
||||
|
||||
var storageFolder = await folder.CreateFolderAsync(Constants.EmojisTempFileFolder, CreationCollisionOption.OpenIfExists);
|
||||
|
||||
ZipFileCreatorHelper.ExtractZipFile(file.Path, storageFolder.Path);
|
||||
|
||||
var fileNames = await storageFolder.GetFilesAsync();
|
||||
|
||||
var nameId = string.Empty;
|
||||
|
||||
var action = new EmoticonAction();
|
||||
|
||||
if (fileNames != null && fileNames.Count > 0)
|
||||
{
|
||||
foreach (var fileItem in fileNames)
|
||||
{
|
||||
if (fileItem.Name.Contains("manifest"))
|
||||
{
|
||||
var text = await FileIO.ReadTextAsync(fileItem);
|
||||
|
||||
var emojisFileInfo = JsonSerializer.Deserialize<EmojisFileManifest>(text) ?? throw new Exception("表情不存在");
|
||||
action.Name = emojisFileInfo.Name;
|
||||
action.NameId = emojisFileInfo.NameId;
|
||||
action.Desc = emojisFileInfo.Description;
|
||||
action.EmojisType = emojisFileInfo.EmojisType;
|
||||
action.HasAction = emojisFileInfo.HasAction;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fileItem.FileType == ".mp4")
|
||||
{
|
||||
action.EmojisVideoPath = fileItem.Path;
|
||||
}
|
||||
else if (fileItem.FileType == ".png" ||
|
||||
fileItem.FileType == ".jpg" ||
|
||||
fileItem.FileType == ".jpeg")
|
||||
{
|
||||
action.Avatar = fileItem.Path;
|
||||
}
|
||||
else if (fileItem.FileType == ".json")
|
||||
{
|
||||
action.EmojisActionPath = fileItem.Path;
|
||||
}
|
||||
|
||||
//var actionFolder = await folder.CreateFolderAsync(Constants.EmojisFolder, CreationCollisionOption.OpenIfExists);
|
||||
|
||||
//var storageFile = await actionFolder
|
||||
// .CreateFileAsync(fileItem.Name, CreationCollisionOption.FailIfExists);
|
||||
|
||||
//await FileIO.WriteBytesAsync(storageFile, await fileItem.ReadBytesAsync());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
var list = (await _localSettingsService
|
||||
.ReadSettingAsync<List<EmoticonAction>>(Constants.EmojisActionListKey)) ?? new List<EmoticonAction>();
|
||||
|
||||
if (list.Where(e => e.NameId == nameId).Any() || Constants.EMOJI_ACTION_LIST.Where(e => e.NameId == nameId).Any())
|
||||
{
|
||||
ToastHelper.SendToast("EmojisNameIdAlreadyExists".GetLocalized(), TimeSpan.FromSeconds(3));
|
||||
|
||||
return;
|
||||
}
|
||||
var actions = new List<EmoticonAction>()
|
||||
{
|
||||
action
|
||||
};
|
||||
|
||||
list.AddRange(actions);
|
||||
|
||||
await _localSettingsService.SaveSettingAsync<List<EmoticonAction>>(Constants.EmojisActionListKey, list);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ToastHelper.SendToast($"导入失败-{ex.Message}", TimeSpan.FromSeconds(3));
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
public async void DelEmojis(object? obj)
|
||||
{
|
||||
|
||||
@@ -59,8 +59,22 @@
|
||||
<RowDefinition Height="auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel>
|
||||
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
|
||||
<AppBarButton
|
||||
x:Uid="ImportEmojisFileBtn"
|
||||
Margin="8"
|
||||
HorizontalAlignment="Right"
|
||||
Command="{x:Bind ViewModel.ImportEmojisFileCommand}"
|
||||
Foreground="{ThemeResource SystemAccentColor}">
|
||||
<AppBarButton.Icon>
|
||||
<FontIcon
|
||||
FontFamily="/Assets/Font/Segoe Fluent Icons.ttf#Segoe Fluent Icons"
|
||||
FontWeight="Bold"
|
||||
Glyph="" />
|
||||
</AppBarButton.Icon>
|
||||
</AppBarButton>
|
||||
<AppBarButton
|
||||
Margin="8"
|
||||
x:Uid="AddEmojisBtn"
|
||||
HorizontalAlignment="Right"
|
||||
Command="{x:Bind ViewModel.OpenEmojisEditDialogCommand}"
|
||||
@@ -69,7 +83,7 @@
|
||||
<FontIcon
|
||||
FontFamily="/Assets/Font/Segoe Fluent Icons.ttf#Segoe Fluent Icons"
|
||||
FontWeight="Bold"
|
||||
Glyph="" />
|
||||
Glyph="" />
|
||||
</AppBarButton.Icon>
|
||||
</AppBarButton>
|
||||
</StackPanel>
|
||||
|
||||
Reference in New Issue
Block a user