89 lines
2.8 KiB
C#
89 lines
2.8 KiB
C#
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using MCI18n.Utilities;
|
|
using Microsoft.Win32;
|
|
using SharpNBT;
|
|
using SharpNBT.SNBT;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace MCI18n
|
|
{
|
|
public partial class MainWindowViewModel : ObservableObject
|
|
{
|
|
|
|
[ObservableProperty]
|
|
private string _currentFilePath;
|
|
|
|
|
|
[RelayCommand]
|
|
private void LoadQuests()
|
|
{
|
|
var openFileDialog = new OpenFileDialog
|
|
{
|
|
Filter = "SNBT Files (*.snbt)|*.snbt|All Files (*.*)|*.*",
|
|
Title = "选择SNBT文件"
|
|
};
|
|
|
|
if (openFileDialog.ShowDialog() == true)
|
|
{
|
|
try
|
|
{
|
|
CurrentFilePath = openFileDialog.FileName;
|
|
//var questData = SNBTParser.LoadFromFile<QuestData>(CurrentFilePath);
|
|
var questData = StringNbt.Parse(File.ReadAllText(CurrentFilePath));
|
|
//if (questData != null)
|
|
//{
|
|
// //QuestList = new ObservableCollection<QuestData> { questData };
|
|
// //SelectedQuest = questData;
|
|
//}
|
|
//else
|
|
//{
|
|
// //QuestList = new ObservableCollection<QuestData>();
|
|
// //SelectedQuest = null;
|
|
//}
|
|
//var fileContent = File.ReadAllText(CurrentFilePath, Encoding.UTF8);
|
|
//var parser = new NbtTagParser();
|
|
//var snbtData = parser.Parse(fileContent);
|
|
// var datas = SNBTParser.LoadFromFile(CurrentFilePath).Parse();
|
|
|
|
// 解析SNBT文件
|
|
//var data = SNBTParser.ParseFile(CurrentFilePath);
|
|
//NbtFile.Write(CurrentFilePath + ".r", questData, FormatOptions.None);
|
|
//StringNbt.SaveToFile(questData, CurrentFilePath + ".r",prettyPrint:true);
|
|
SnbtWriter.SaveToFile(questData, CurrentFilePath + ".r", prettyPrint: true);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"加载文件失败: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
}
|
|
}
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void SaveQuest()
|
|
{
|
|
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void SaveQuestAs()
|
|
{
|
|
|
|
}
|
|
|
|
[RelayCommand]
|
|
private void CreateNewQuest()
|
|
{
|
|
|
|
}
|
|
}
|
|
} |