-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
支持导入/导出SRGF格式抽卡记录
- Loading branch information
Showing
7 changed files
with
311 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
using Microsoft.UI.Xaml; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.Encodings.Web; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using Windows.Storage.Pickers; | ||
using Windows.Storage; | ||
|
||
namespace SRTools.Depend | ||
{ | ||
public class ExportSRGF | ||
{ | ||
public class Info | ||
{ | ||
public string uid { get; set; } | ||
public string lang { get; set; } | ||
public int region_time_zone { get; set; } | ||
public int export_timestamp { get; set; } | ||
public string export_app { get; set; } | ||
public string export_app_version { get; set; } | ||
public string srgf_version { get; set; } | ||
} | ||
|
||
public class OItem | ||
{ | ||
public string Uid { get; set; } | ||
public string GachaId { get; set; } | ||
public string GachaType { get; set; } | ||
public string ItemId { get; set; } | ||
public string Count { get; set; } | ||
public string Time { get; set; } | ||
public string Name { get; set; } | ||
public string Lang { get; set; } | ||
public string ItemType { get; set; } | ||
public string RankType { get; set; } | ||
public string Id { get; set; } | ||
} | ||
|
||
public class Item | ||
{ | ||
public string gacha_id { get; set; } | ||
public string gacha_type { get; set; } | ||
public string item_id { get; set; } | ||
public string count { get; set; } | ||
public string time { get; set; } | ||
public string name { get; set; } | ||
public string item_type { get; set; } | ||
public string rank_type { get; set; } | ||
public string id { get; set; } | ||
} | ||
|
||
public Info info { get; set; } | ||
public List<Item> list { get; set; } | ||
|
||
public ExportSRGF() | ||
{ | ||
info = new Info(); | ||
list = new List<Item>(); | ||
} | ||
|
||
public string ToJson() | ||
{ | ||
return JsonSerializer.Serialize(this); | ||
} | ||
|
||
public async void ExportAll() | ||
{ | ||
// 定义一个空的列表,用于存储所有的ExportSRGF.OItem对象 | ||
var oitems = new List<ExportSRGF.OItem>(); | ||
|
||
// 读取每个文件的内容,并将其反序列化为一个List<ExportSRGF.OItem>对象 | ||
var srtoolsFolder = await KnownFolders.DocumentsLibrary.GetFolderAsync("JSG-LLC\\SRTools"); | ||
var files = new List<string> { "GachaRecords_Character.ini", "GachaRecords_LightCone.ini", "GachaRecords_Newbie.ini", "GachaRecords_Regular.ini" }; | ||
foreach (var fileName in files) | ||
{ | ||
var file1 = await srtoolsFolder.GetFileAsync(fileName); | ||
var json1 = await FileIO.ReadTextAsync(file1); | ||
var list = JsonSerializer.Deserialize<List<ExportSRGF.OItem>>(json1); | ||
|
||
// 将每个List<ExportSRGF.OItem>对象中的所有元素添加到oitems列表中 | ||
oitems.AddRange(list); | ||
} | ||
|
||
// 序列化oitems列表为JSON字符串 | ||
string jsonOutput = JsonSerializer.Serialize(oitems); | ||
List<Item> items = oitems.Select(oItem => new Item | ||
{ | ||
gacha_id = oItem.GachaId, | ||
gacha_type = oItem.GachaType, | ||
item_id = oItem.ItemId, | ||
count = oItem.Count, | ||
time = oItem.Time, | ||
name = oItem.Name, | ||
item_type = oItem.ItemType, | ||
rank_type = oItem.RankType, | ||
id = oItem.Id | ||
}).ToList(); | ||
ExportSRGF data = new ExportSRGF(); | ||
var uid = oitems.FirstOrDefault()?.Uid; | ||
data.info.uid = uid; | ||
data.info.lang = "zh-cn"; | ||
data.info.region_time_zone = 8; | ||
data.info.export_timestamp = 1684124992; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
data.info.export_app = "SRTools"; | ||
data.info.export_app_version = "1.1.2.0"; | ||
data.info.srgf_version = "v1.0"; | ||
data.list = items; | ||
|
||
// 配置JsonSerializerOptions对象,设置Encoder属性为不转义中文字符的JavaScriptEncoder | ||
var options = new JsonSerializerOptions | ||
{ | ||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, | ||
WriteIndented = true // 设置缩进以便更易于阅读 | ||
}; | ||
|
||
// 将数据模板转换为JSON字符串 | ||
string json = JsonSerializer.Serialize(data, options); | ||
|
||
// 创建文件保存对话框 | ||
DateTime now = DateTime.Now; | ||
string formattedDate = now.ToString("yyyy_MM_dd_HH_mm_ss"); | ||
var savePicker = new FileSavePicker(); | ||
savePicker.FileTypeChoices.Add("Star Rail GachaLog Format standard (SRGF) v1.0", new List<string>() { ".json" }); | ||
savePicker.SuggestedFileName = "SRTools_Gacha_Export_"+data.info.uid+"_" + formattedDate; | ||
var window = new Window(); | ||
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window); | ||
WinRT.Interop.InitializeWithWindow.Initialize(savePicker, hwnd); | ||
|
||
// 显示文件保存对话框 | ||
StorageFile file = await savePicker.PickSaveFileAsync(); | ||
if (file != null) | ||
{ | ||
// 将字符串写入文件 | ||
await FileIO.WriteTextAsync(file, json); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using Microsoft.UI.Xaml; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using Windows.Storage; | ||
using Windows.Storage.Pickers; | ||
|
||
public class ImportSRGF | ||
{ | ||
public class Info | ||
{ | ||
public string uid { get; set; } | ||
public string lang { get; set; } | ||
public int region_time_zone { get; set; } | ||
public int export_timestamp { get; set; } | ||
public string export_app { get; set; } | ||
public string export_app_version { get; set; } | ||
public string srgf_version { get; set; } | ||
} | ||
|
||
public class OItem | ||
{ | ||
public string Uid { get; set; } | ||
public string GachaId { get; set; } | ||
public string GachaType { get; set; } | ||
public string ItemId { get; set; } | ||
public string Count { get; set; } | ||
public string Time { get; set; } | ||
public string Name { get; set; } | ||
public string Lang { get; set; } | ||
public string ItemType { get; set; } | ||
public string RankType { get; set; } | ||
public string Id { get; set; } | ||
} | ||
|
||
public class Item | ||
{ | ||
public string gacha_id { get; set; } | ||
public string gacha_type { get; set; } | ||
public string item_id { get; set; } | ||
public string count { get; set; } | ||
public string time { get; set; } | ||
public string name { get; set; } | ||
public string item_type { get; set; } | ||
public string rank_type { get; set; } | ||
public string id { get; set; } | ||
} | ||
|
||
public Info info { get; set; } | ||
public List<Item> list { get; set; } | ||
|
||
|
||
public async Task Main() | ||
{ | ||
// 导入原始 JSON 数据 | ||
var picker = new FileOpenPicker(); | ||
picker.FileTypeFilter.Add(".json"); | ||
var window = new Window(); | ||
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window); | ||
WinRT.Interop.InitializeWithWindow.Initialize(picker, hwnd); | ||
var file = await picker.PickSingleFileAsync(); | ||
string jsonData = File.ReadAllText(file.Path); | ||
var srgfData = System.Text.Json.JsonSerializer.Deserialize<ImportSRGF>(jsonData); | ||
|
||
// 获取 uid | ||
var uid = srgfData.info?.uid; | ||
|
||
// 创建四个不同的列表 | ||
List<OItem> gachaCharacterList = new List<OItem>(); | ||
List<OItem> gachaLightConeList = new List<OItem>(); | ||
List<OItem> gachaNewbieList = new List<OItem>(); | ||
List<OItem> gachaRegularList = new List<OItem>(); | ||
|
||
// 根据导入的数据进行拆分并转换为 OItem | ||
foreach (var item in srgfData.list) | ||
{ | ||
OItem oItem = new OItem | ||
{ | ||
Uid = uid, | ||
GachaId = item.gacha_id, | ||
GachaType = item.gacha_type, | ||
ItemId = item.item_id, | ||
Count = item.count, | ||
Time = item.time, | ||
Name = item.name, | ||
Lang = srgfData.info.lang, | ||
ItemType = item.item_type, | ||
RankType = item.rank_type, | ||
Id = item.id | ||
}; | ||
|
||
// 根据 gacha_type 添加到对应的列表 | ||
if (item.gacha_type == "11") | ||
gachaCharacterList.Add(oItem); | ||
else if (item.gacha_type == "12") | ||
gachaLightConeList.Add(oItem); | ||
else if (item.gacha_type == "2") | ||
gachaNewbieList.Add(oItem); | ||
else if (item.gacha_type == "1") | ||
gachaRegularList.Add(oItem); | ||
} | ||
|
||
var folder = KnownFolders.DocumentsLibrary; | ||
var srtoolsFolder = await folder.CreateFolderAsync("JSG-LLC\\SRTools", CreationCollisionOption.OpenIfExists); | ||
|
||
// 导出 GachaRecords_Character JSON | ||
string gachaCharacterJson = JsonSerializer.Serialize(gachaCharacterList); | ||
File.WriteAllText(srtoolsFolder.Path + "\\GachaRecords_Character.ini", gachaCharacterJson); | ||
|
||
// 导出 GachaRecords_LightCone JSON | ||
string gachaLightConeJson = JsonSerializer.Serialize(gachaLightConeList); | ||
File.WriteAllText(srtoolsFolder.Path + "\\GachaRecords_LightCone.ini", gachaLightConeJson); | ||
|
||
// 导出 GachaRecords_Newbie JSON | ||
string gachaNewbieJson = JsonSerializer.Serialize(gachaNewbieList); | ||
File.WriteAllText(srtoolsFolder.Path + "\\GachaRecords_Newbie.ini", gachaNewbieJson); | ||
|
||
// 导出 GachaRecords_Regular JSON | ||
string gachaRegularJson = JsonSerializer.Serialize(gachaRegularList); | ||
File.WriteAllText(srtoolsFolder.Path + "\\GachaRecords_Regular.ini", gachaRegularJson); | ||
|
||
Console.WriteLine("拆分并导出 JSON 文件完成。"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
?怎么导出时间戳会是个常量