mirror of
https://github.com/jie65535/GrasscutterCommandGenerator.git
synced 2026-11-06 15:21:59 +08:00
Add remote resource support to DEBUG tools
This commit is contained in:
1 parent
240a64e47f
commit
d90cb70241
7 files changed
+767
-172
No files matched your search
+154
-59
@@ -1,4 +1,4 @@
|
||||
namespace GrasscutterTools.Pages
|
||||
namespace GrasscutterTools.Pages
|
||||
{
|
||||
partial class PageTools
|
||||
{
|
||||
@@ -28,100 +28,187 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.BtnUpdateResources = new System.Windows.Forms.Button();
|
||||
this.LblProjectResRoot = new System.Windows.Forms.Label();
|
||||
this.TxtProjectResRoot = new System.Windows.Forms.TextBox();
|
||||
this.LblGcResRoot = new System.Windows.Forms.Label();
|
||||
this.TxtGcResRoot = new System.Windows.Forms.TextBox();
|
||||
this.LblResourceSource = new System.Windows.Forms.Label();
|
||||
this.CmbResourceSource = new System.Windows.Forms.ComboBox();
|
||||
this.LblRemoteRepository = new System.Windows.Forms.Label();
|
||||
this.TxtRemoteRepository = new System.Windows.Forms.TextBox();
|
||||
this.LblRemoteBranch = new System.Windows.Forms.Label();
|
||||
this.TxtRemoteBranch = new System.Windows.Forms.TextBox();
|
||||
this.LblRemoteToken = new System.Windows.Forms.Label();
|
||||
this.TxtRemoteToken = new System.Windows.Forms.TextBox();
|
||||
this.BtnGenerateToken = new System.Windows.Forms.Button();
|
||||
this.BtnUpdateAllResources = new System.Windows.Forms.Button();
|
||||
this.BtnUpdateActivity = new System.Windows.Forms.Button();
|
||||
this.BtnUpdateBannerTitles = new System.Windows.Forms.Button();
|
||||
this.PrgUpdateResources = new System.Windows.Forms.ProgressBar();
|
||||
this.LblUpdateProgress = new System.Windows.Forms.Label();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// BtnUpdateResources
|
||||
//
|
||||
this.BtnUpdateResources.Location = new System.Drawing.Point(41, 195);
|
||||
this.BtnUpdateResources.Name = "BtnUpdateResources";
|
||||
this.BtnUpdateResources.Size = new System.Drawing.Size(100, 30);
|
||||
this.BtnUpdateResources.TabIndex = 0;
|
||||
this.BtnUpdateResources.Text = "Update res";
|
||||
this.BtnUpdateResources.UseVisualStyleBackColor = true;
|
||||
this.BtnUpdateResources.Click += new System.EventHandler(this.BtnUpdateResources_Click);
|
||||
//
|
||||
//
|
||||
// LblProjectResRoot
|
||||
//
|
||||
//
|
||||
this.LblProjectResRoot.AutoSize = true;
|
||||
this.LblProjectResRoot.Location = new System.Drawing.Point(38, 34);
|
||||
this.LblProjectResRoot.Location = new System.Drawing.Point(38, 12);
|
||||
this.LblProjectResRoot.Name = "LblProjectResRoot";
|
||||
this.LblProjectResRoot.Size = new System.Drawing.Size(141, 17);
|
||||
this.LblProjectResRoot.TabIndex = 1;
|
||||
this.LblProjectResRoot.Text = "项目 Resources/ 路径:";
|
||||
//
|
||||
//
|
||||
// TxtProjectResRoot
|
||||
//
|
||||
this.TxtProjectResRoot.Location = new System.Drawing.Point(185, 31);
|
||||
//
|
||||
this.TxtProjectResRoot.Location = new System.Drawing.Point(185, 9);
|
||||
this.TxtProjectResRoot.Name = "TxtProjectResRoot";
|
||||
this.TxtProjectResRoot.Size = new System.Drawing.Size(413, 23);
|
||||
this.TxtProjectResRoot.TabIndex = 2;
|
||||
//
|
||||
//
|
||||
// LblGcResRoot
|
||||
//
|
||||
//
|
||||
this.LblGcResRoot.AutoSize = true;
|
||||
this.LblGcResRoot.Location = new System.Drawing.Point(44, 63);
|
||||
this.LblGcResRoot.Location = new System.Drawing.Point(38, 68);
|
||||
this.LblGcResRoot.Name = "LblGcResRoot";
|
||||
this.LblGcResRoot.Size = new System.Drawing.Size(135, 17);
|
||||
this.LblGcResRoot.TabIndex = 3;
|
||||
this.LblGcResRoot.Text = "GC_Resources/ 路径:";
|
||||
//
|
||||
this.LblGcResRoot.Text = "本地 GC_Resources/:";
|
||||
//
|
||||
// TxtGcResRoot
|
||||
//
|
||||
this.TxtGcResRoot.Location = new System.Drawing.Point(185, 60);
|
||||
//
|
||||
this.TxtGcResRoot.Location = new System.Drawing.Point(185, 65);
|
||||
this.TxtGcResRoot.Name = "TxtGcResRoot";
|
||||
this.TxtGcResRoot.Size = new System.Drawing.Size(413, 23);
|
||||
this.TxtGcResRoot.TabIndex = 4;
|
||||
//
|
||||
//
|
||||
// LblResourceSource
|
||||
//
|
||||
this.LblResourceSource.AutoSize = true;
|
||||
this.LblResourceSource.Location = new System.Drawing.Point(38, 40);
|
||||
this.LblResourceSource.Name = "LblResourceSource";
|
||||
this.LblResourceSource.Size = new System.Drawing.Size(141, 17);
|
||||
this.LblResourceSource.TabIndex = 5;
|
||||
this.LblResourceSource.Text = "GC_Resources 来源:";
|
||||
//
|
||||
// CmbResourceSource
|
||||
//
|
||||
this.CmbResourceSource.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.CmbResourceSource.FormattingEnabled = true;
|
||||
this.CmbResourceSource.Items.AddRange(new object[] {
|
||||
"本地目录",
|
||||
"远程 GitLab 仓库"});
|
||||
this.CmbResourceSource.Location = new System.Drawing.Point(185, 37);
|
||||
this.CmbResourceSource.Name = "CmbResourceSource";
|
||||
this.CmbResourceSource.Size = new System.Drawing.Size(200, 25);
|
||||
this.CmbResourceSource.TabIndex = 6;
|
||||
this.CmbResourceSource.SelectedIndexChanged += new System.EventHandler(this.CmbResourceSource_SelectedIndexChanged);
|
||||
//
|
||||
// LblRemoteRepository
|
||||
//
|
||||
this.LblRemoteRepository.AutoSize = true;
|
||||
this.LblRemoteRepository.Location = new System.Drawing.Point(38, 96);
|
||||
this.LblRemoteRepository.Name = "LblRemoteRepository";
|
||||
this.LblRemoteRepository.Size = new System.Drawing.Size(141, 17);
|
||||
this.LblRemoteRepository.TabIndex = 7;
|
||||
this.LblRemoteRepository.Text = "远程仓库地址:";
|
||||
//
|
||||
// TxtRemoteRepository
|
||||
//
|
||||
this.TxtRemoteRepository.Location = new System.Drawing.Point(185, 93);
|
||||
this.TxtRemoteRepository.Name = "TxtRemoteRepository";
|
||||
this.TxtRemoteRepository.Size = new System.Drawing.Size(413, 23);
|
||||
this.TxtRemoteRepository.TabIndex = 8;
|
||||
//
|
||||
// LblRemoteBranch
|
||||
//
|
||||
this.LblRemoteBranch.AutoSize = true;
|
||||
this.LblRemoteBranch.Location = new System.Drawing.Point(38, 125);
|
||||
this.LblRemoteBranch.Name = "LblRemoteBranch";
|
||||
this.LblRemoteBranch.Size = new System.Drawing.Size(141, 17);
|
||||
this.LblRemoteBranch.TabIndex = 9;
|
||||
this.LblRemoteBranch.Text = "远程分支:";
|
||||
//
|
||||
// TxtRemoteBranch
|
||||
//
|
||||
this.TxtRemoteBranch.Location = new System.Drawing.Point(185, 122);
|
||||
this.TxtRemoteBranch.Name = "TxtRemoteBranch";
|
||||
this.TxtRemoteBranch.Size = new System.Drawing.Size(200, 23);
|
||||
this.TxtRemoteBranch.TabIndex = 10;
|
||||
//
|
||||
// LblRemoteToken
|
||||
//
|
||||
this.LblRemoteToken.AutoSize = true;
|
||||
this.LblRemoteToken.Location = new System.Drawing.Point(38, 154);
|
||||
this.LblRemoteToken.Name = "LblRemoteToken";
|
||||
this.LblRemoteToken.Size = new System.Drawing.Size(141, 17);
|
||||
this.LblRemoteToken.TabIndex = 11;
|
||||
this.LblRemoteToken.Text = "GitLab Token:";
|
||||
//
|
||||
// TxtRemoteToken
|
||||
//
|
||||
this.TxtRemoteToken.Location = new System.Drawing.Point(185, 151);
|
||||
this.TxtRemoteToken.Name = "TxtRemoteToken";
|
||||
this.TxtRemoteToken.PasswordChar = '*';
|
||||
this.TxtRemoteToken.Size = new System.Drawing.Size(310, 23);
|
||||
this.TxtRemoteToken.TabIndex = 12;
|
||||
//
|
||||
// BtnGenerateToken
|
||||
//
|
||||
this.BtnGenerateToken.Location = new System.Drawing.Point(501, 149);
|
||||
this.BtnGenerateToken.Name = "BtnGenerateToken";
|
||||
this.BtnGenerateToken.Size = new System.Drawing.Size(97, 27);
|
||||
this.BtnGenerateToken.TabIndex = 13;
|
||||
this.BtnGenerateToken.Text = "生成 Token";
|
||||
this.BtnGenerateToken.UseVisualStyleBackColor = true;
|
||||
this.BtnGenerateToken.Click += new System.EventHandler(this.BtnGenerateToken_Click);
|
||||
//
|
||||
// BtnUpdateAllResources
|
||||
//
|
||||
this.BtnUpdateAllResources.Location = new System.Drawing.Point(41, 100);
|
||||
//
|
||||
this.BtnUpdateAllResources.Location = new System.Drawing.Point(41, 190);
|
||||
this.BtnUpdateAllResources.Name = "BtnUpdateAllResources";
|
||||
this.BtnUpdateAllResources.Size = new System.Drawing.Size(150, 30);
|
||||
this.BtnUpdateAllResources.Size = new System.Drawing.Size(180, 30);
|
||||
this.BtnUpdateAllResources.TabIndex = 0;
|
||||
this.BtnUpdateAllResources.Text = "Update All Resources";
|
||||
this.BtnUpdateAllResources.UseVisualStyleBackColor = true;
|
||||
this.BtnUpdateAllResources.Click += new System.EventHandler(this.BtnUpdateAllResources_Click);
|
||||
//
|
||||
// BtnUpdateActivity
|
||||
//
|
||||
this.BtnUpdateActivity.Location = new System.Drawing.Point(197, 100);
|
||||
this.BtnUpdateActivity.Name = "BtnUpdateActivity";
|
||||
this.BtnUpdateActivity.Size = new System.Drawing.Size(150, 30);
|
||||
this.BtnUpdateActivity.TabIndex = 0;
|
||||
this.BtnUpdateActivity.Text = "Update Activity";
|
||||
this.BtnUpdateActivity.UseVisualStyleBackColor = true;
|
||||
this.BtnUpdateActivity.Click += new System.EventHandler(this.BtnUpdateActivity_Click);
|
||||
//
|
||||
// BtnUpdateBannerTitles
|
||||
//
|
||||
this.BtnUpdateBannerTitles.Location = new System.Drawing.Point(353, 100);
|
||||
this.BtnUpdateBannerTitles.Name = "BtnUpdateBannerTitles";
|
||||
this.BtnUpdateBannerTitles.Size = new System.Drawing.Size(150, 30);
|
||||
this.BtnUpdateBannerTitles.TabIndex = 0;
|
||||
this.BtnUpdateBannerTitles.Text = "Update Banner Titles";
|
||||
this.BtnUpdateBannerTitles.UseVisualStyleBackColor = true;
|
||||
this.BtnUpdateBannerTitles.Click += new System.EventHandler(this.BtnUpdateBannerTitles_Click);
|
||||
//
|
||||
//
|
||||
// PrgUpdateResources
|
||||
//
|
||||
this.PrgUpdateResources.Location = new System.Drawing.Point(235, 195);
|
||||
this.PrgUpdateResources.Name = "PrgUpdateResources";
|
||||
this.PrgUpdateResources.Size = new System.Drawing.Size(363, 20);
|
||||
this.PrgUpdateResources.Style = System.Windows.Forms.ProgressBarStyle.Continuous;
|
||||
this.PrgUpdateResources.TabIndex = 14;
|
||||
this.PrgUpdateResources.Visible = false;
|
||||
//
|
||||
// LblUpdateProgress
|
||||
//
|
||||
this.LblUpdateProgress.AutoEllipsis = true;
|
||||
this.LblUpdateProgress.AutoSize = false;
|
||||
this.LblUpdateProgress.Location = new System.Drawing.Point(235, 218);
|
||||
this.LblUpdateProgress.Name = "LblUpdateProgress";
|
||||
this.LblUpdateProgress.Size = new System.Drawing.Size(363, 17);
|
||||
this.LblUpdateProgress.TabIndex = 15;
|
||||
this.LblUpdateProgress.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||
this.LblUpdateProgress.Visible = false;
|
||||
//
|
||||
// PageTools
|
||||
//
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.BtnGenerateToken);
|
||||
this.Controls.Add(this.TxtRemoteToken);
|
||||
this.Controls.Add(this.LblRemoteToken);
|
||||
this.Controls.Add(this.TxtRemoteBranch);
|
||||
this.Controls.Add(this.LblRemoteBranch);
|
||||
this.Controls.Add(this.TxtRemoteRepository);
|
||||
this.Controls.Add(this.LblRemoteRepository);
|
||||
this.Controls.Add(this.CmbResourceSource);
|
||||
this.Controls.Add(this.LblResourceSource);
|
||||
this.Controls.Add(this.TxtGcResRoot);
|
||||
this.Controls.Add(this.LblGcResRoot);
|
||||
this.Controls.Add(this.TxtProjectResRoot);
|
||||
this.Controls.Add(this.LblProjectResRoot);
|
||||
this.Controls.Add(this.BtnUpdateBannerTitles);
|
||||
this.Controls.Add(this.BtnUpdateActivity);
|
||||
this.Controls.Add(this.BtnUpdateAllResources);
|
||||
this.Controls.Add(this.BtnUpdateResources);
|
||||
this.Controls.Add(this.LblUpdateProgress);
|
||||
this.Controls.Add(this.PrgUpdateResources);
|
||||
this.Name = "PageTools";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
@@ -130,13 +217,21 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button BtnUpdateResources;
|
||||
private System.Windows.Forms.Label LblProjectResRoot;
|
||||
private System.Windows.Forms.TextBox TxtProjectResRoot;
|
||||
private System.Windows.Forms.Label LblGcResRoot;
|
||||
private System.Windows.Forms.TextBox TxtGcResRoot;
|
||||
private System.Windows.Forms.Label LblResourceSource;
|
||||
private System.Windows.Forms.ComboBox CmbResourceSource;
|
||||
private System.Windows.Forms.Label LblRemoteRepository;
|
||||
private System.Windows.Forms.TextBox TxtRemoteRepository;
|
||||
private System.Windows.Forms.Label LblRemoteBranch;
|
||||
private System.Windows.Forms.TextBox TxtRemoteBranch;
|
||||
private System.Windows.Forms.Label LblRemoteToken;
|
||||
private System.Windows.Forms.TextBox TxtRemoteToken;
|
||||
private System.Windows.Forms.Button BtnGenerateToken;
|
||||
private System.Windows.Forms.Button BtnUpdateAllResources;
|
||||
private System.Windows.Forms.Button BtnUpdateActivity;
|
||||
private System.Windows.Forms.Button BtnUpdateBannerTitles;
|
||||
private System.Windows.Forms.ProgressBar PrgUpdateResources;
|
||||
private System.Windows.Forms.Label LblUpdateProgress;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@@ -29,6 +31,7 @@ using GrasscutterTools.Game;
|
||||
using GrasscutterTools.Game.Activity;
|
||||
using GrasscutterTools.Game.Data;
|
||||
using GrasscutterTools.Properties;
|
||||
using GrasscutterTools.Utils;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@@ -36,6 +39,22 @@ namespace GrasscutterTools.Pages
|
||||
{
|
||||
internal partial class PageTools : BasePage
|
||||
{
|
||||
private const string LogTag = nameof(PageTools);
|
||||
|
||||
private sealed class UpdateProgressInfo
|
||||
{
|
||||
public UpdateProgressInfo(int value, string message)
|
||||
{
|
||||
Value = value;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public int Value { get; }
|
||||
public string Message { get; }
|
||||
}
|
||||
|
||||
private bool _updateInProgress;
|
||||
|
||||
public override string Text => "Tools";
|
||||
|
||||
public PageTools()
|
||||
@@ -47,140 +66,257 @@ namespace GrasscutterTools.Pages
|
||||
{
|
||||
TxtGcResRoot.Text = Settings.Default.ResourcesDirPath;
|
||||
TxtProjectResRoot.Text = Settings.Default.ProjectResourcePath;
|
||||
TxtRemoteRepository.Text = string.IsNullOrWhiteSpace(Settings.Default.RemoteResourceRepository)
|
||||
? RemoteResourceRepositoryDefault
|
||||
: Settings.Default.RemoteResourceRepository;
|
||||
TxtRemoteBranch.Text = string.IsNullOrWhiteSpace(Settings.Default.RemoteResourceBranch)
|
||||
? RemoteResourceBranchDefault
|
||||
: Settings.Default.RemoteResourceBranch;
|
||||
TxtRemoteToken.Text = Settings.Default.RemoteResourceToken;
|
||||
CmbResourceSource.SelectedIndex = Settings.Default.UseRemoteResourceRepository ? 1 : 0;
|
||||
UpdateResourceSourceControls();
|
||||
}
|
||||
|
||||
private void BtnUpdateResources_Click(object sender, EventArgs e)
|
||||
private const string RemoteResourceRepositoryDefault = "https://gitlab.com/Dimbreath/animegamedata2";
|
||||
private const string RemoteResourceBranchDefault = "main";
|
||||
|
||||
private void CmbResourceSource_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
var src = new OpenFileDialog
|
||||
{
|
||||
Title = "请选择当前原文件",
|
||||
Multiselect = false,
|
||||
};
|
||||
var dest = new OpenFileDialog
|
||||
{
|
||||
Title = "请选择包含新ID的文件",
|
||||
Multiselect = false,
|
||||
};
|
||||
UpdateResourceSourceControls();
|
||||
}
|
||||
|
||||
if (src.ShowDialog() == DialogResult.OK && dest.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
var srcLines = File.ReadAllLines(src.FileName);
|
||||
var srcDic = new Dictionary<string, string>(srcLines.Length);
|
||||
foreach (var line in srcLines)
|
||||
{
|
||||
var sp = line.IndexOf(':');
|
||||
if (sp > 0)
|
||||
{
|
||||
var value = line.Substring(sp + 1).Trim();
|
||||
if (!value.StartsWith("[N/A]"))
|
||||
srcDic[line.Substring(0, sp).Trim()] = line.Substring(sp + 1).Trim();
|
||||
}
|
||||
}
|
||||
private void UpdateResourceSourceControls()
|
||||
{
|
||||
var useRemote = CmbResourceSource.SelectedIndex == 1;
|
||||
TxtGcResRoot.Enabled = !useRemote;
|
||||
TxtRemoteRepository.Enabled = useRemote;
|
||||
TxtRemoteBranch.Enabled = useRemote;
|
||||
TxtRemoteToken.Enabled = useRemote;
|
||||
BtnGenerateToken.Enabled = useRemote;
|
||||
}
|
||||
|
||||
var destLines = File.ReadAllLines(dest.FileName);
|
||||
using (var outStream = File.Create(dest.FileName))
|
||||
using (var outTxtStream = new StreamWriter(outStream))
|
||||
{
|
||||
foreach (var line in destLines)
|
||||
{
|
||||
var sp = line.IndexOf(':');
|
||||
if (sp == -1)
|
||||
{
|
||||
outTxtStream.WriteLine(line);
|
||||
}
|
||||
else
|
||||
{
|
||||
var key = line.Substring(0, sp).Trim();
|
||||
if (!srcDic.TryGetValue(key, out var value))
|
||||
value = line.Substring(sp + 1).Trim();
|
||||
outTxtStream.WriteLine($"{key}:{value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void BtnGenerateToken_Click(object sender, EventArgs e)
|
||||
{
|
||||
UIUtil.OpenURL("https://gitlab.com/-/user_settings/personal_access_tokens?name=GrasscutterTools&scopes=read_api,read_repository");
|
||||
}
|
||||
|
||||
public override void OnClosed()
|
||||
{
|
||||
SaveResourceSettings();
|
||||
}
|
||||
|
||||
private void SaveResourceSettings()
|
||||
{
|
||||
Settings.Default.ResourcesDirPath = TxtGcResRoot.Text;
|
||||
Settings.Default.ProjectResourcePath = TxtProjectResRoot.Text;
|
||||
Settings.Default.RemoteResourceRepository = TxtRemoteRepository.Text.Trim();
|
||||
Settings.Default.RemoteResourceBranch = TxtRemoteBranch.Text.Trim();
|
||||
Settings.Default.RemoteResourceToken = TxtRemoteToken.Text.Trim();
|
||||
Settings.Default.UseRemoteResourceRepository = CmbResourceSource.SelectedIndex == 1;
|
||||
}
|
||||
|
||||
private bool CheckInputPaths()
|
||||
{
|
||||
if (string.IsNullOrEmpty(TxtProjectResRoot.Text) || string.IsNullOrEmpty(TxtGcResRoot.Text))
|
||||
if (string.IsNullOrEmpty(TxtProjectResRoot.Text))
|
||||
{
|
||||
MessageBox.Show("请先填写资源目录路径!", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show("请先填写项目 Resources 路径!", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Directory.Exists(TxtProjectResRoot.Text) && Directory.Exists(TxtGcResRoot.Text))
|
||||
var useRemote = CmbResourceSource.SelectedIndex == 1;
|
||||
if (Directory.Exists(TxtProjectResRoot.Text) &&
|
||||
(useRemote || Directory.Exists(TxtGcResRoot.Text)))
|
||||
{
|
||||
Settings.Default.ResourcesDirPath = TxtGcResRoot.Text;
|
||||
Settings.Default.ProjectResourcePath = TxtProjectResRoot.Text;
|
||||
SaveResourceSettings();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请填写正确的Res路径!", Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show(useRemote ? "请填写正确的项目 Resources 路径!" : "请填写正确的 Res 路径!",
|
||||
Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private TextMapData TextMapData;
|
||||
private GameResources GameResources;
|
||||
|
||||
private void BtnUpdateAllResources_Click(object sender, EventArgs e)
|
||||
private async void BtnUpdateAllResources_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_updateInProgress || !CheckInputPaths())
|
||||
return;
|
||||
|
||||
var useRemote = CmbResourceSource.SelectedIndex == 1;
|
||||
var projectResourcesPath = TxtProjectResRoot.Text.Trim();
|
||||
var localResourcePath = useRemote ? null : TxtGcResRoot.Text.Trim();
|
||||
var repositoryUrl = TxtRemoteRepository.Text.Trim();
|
||||
var branch = TxtRemoteBranch.Text.Trim();
|
||||
var token = TxtRemoteToken.Text.Trim();
|
||||
var progress = new Progress<UpdateProgressInfo>(UpdateProgressOnUi);
|
||||
|
||||
SetUpdateBusy(true);
|
||||
var completed = false;
|
||||
try
|
||||
{
|
||||
if (!CheckInputPaths()) return;
|
||||
|
||||
TextMapData ??= new TextMapData(TxtGcResRoot.Text);
|
||||
GameResources ??= new GameResources(TxtGcResRoot.Text, TextMapData);
|
||||
|
||||
GameResources.ConvertResources(TxtProjectResRoot.Text);
|
||||
MessageBox.Show("OK", Resources.Tips, MessageBoxButtons.OK);
|
||||
await Task.Run(() => RunUpdateAllResourcesAsync(
|
||||
useRemote,
|
||||
localResourcePath,
|
||||
projectResourcesPath,
|
||||
repositoryUrl,
|
||||
branch,
|
||||
token,
|
||||
progress));
|
||||
completed = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.E(LogTag, "更新所有资源失败", ex);
|
||||
MessageBox.Show(ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
SetUpdateBusy(false);
|
||||
}
|
||||
|
||||
if (completed)
|
||||
MessageBox.Show("OK", Resources.Tips, MessageBoxButtons.OK);
|
||||
}
|
||||
|
||||
private void BtnUpdateActivity_Click(object sender, EventArgs e)
|
||||
private async Task RunUpdateAllResourcesAsync(bool useRemote, string localResourcePath,
|
||||
string projectResourcesPath, string repositoryUrl, string branch, string token,
|
||||
IProgress<UpdateProgressInfo> progress)
|
||||
{
|
||||
RemoteResourceLoader remoteSource = null;
|
||||
try
|
||||
{
|
||||
if (!CheckInputPaths()) return;
|
||||
ReportProgress(progress, 0, "开始更新所有资源");
|
||||
string resourcePath;
|
||||
if (useRemote)
|
||||
{
|
||||
ReportProgress(progress, 2, "准备连接远程 GitLab 仓库");
|
||||
remoteSource = await RemoteResourceLoader.DownloadAsync(
|
||||
repositoryUrl,
|
||||
branch,
|
||||
token,
|
||||
includeAllExcelFiles: true,
|
||||
includeActivityFile: true,
|
||||
includeManualTextMap: true,
|
||||
reportProgress: (value, message) => ReportProgress(progress, 5 + value * 40 / 100, message),
|
||||
cancellationToken: CancellationToken.None);
|
||||
resourcePath = remoteSource.DirectoryPath;
|
||||
ReportProgress(progress, 46, "远程资源下载完成");
|
||||
}
|
||||
else
|
||||
{
|
||||
resourcePath = localResourcePath;
|
||||
ReportProgress(progress, 5, "使用本地 GC_Resources 目录");
|
||||
}
|
||||
|
||||
var json = File.ReadAllText(
|
||||
Path.Combine(TxtGcResRoot.Text, "ExcelBinOutput", "NewActivityExcelConfigData.json"),
|
||||
ReportProgress(progress, 48, "加载 TextMap 数据");
|
||||
var textMapData = new TextMapData(resourcePath);
|
||||
ReportProgress(progress, 52, "加载 ExcelBinOutput 数据");
|
||||
var gameResources = new GameResources(resourcePath, textMapData);
|
||||
ReportProgress(progress, 55, "生成基础资源文件");
|
||||
gameResources.ConvertResources(projectResourcesPath);
|
||||
ReportProgress(progress, 72, "基础资源文件生成完成");
|
||||
|
||||
var activityJson = File.ReadAllText(
|
||||
Path.Combine(resourcePath, "ExcelBinOutput", "NewActivityExcelConfigData.json"),
|
||||
Encoding.UTF8);
|
||||
var activityItems = JsonConvert.DeserializeObject<List<NewActivityItem>>(json);
|
||||
var activityItems = JsonConvert.DeserializeObject<List<NewActivityItem>>(activityJson);
|
||||
if (activityItems == null)
|
||||
throw new InvalidDataException("NewActivityExcelConfigData.json 内容无效。");
|
||||
|
||||
TextMapData ??= new TextMapData(TxtGcResRoot.Text);
|
||||
|
||||
// 确保使用中文UI文化加载GameData,防止ConvertResources留下的ru-ru状态
|
||||
ReportProgress(progress, 74, "加载活动名称资源");
|
||||
var savedCulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-cn");
|
||||
GameData.LoadResources();
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture = savedCulture;
|
||||
try
|
||||
{
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-cn");
|
||||
GameData.LoadResources();
|
||||
}
|
||||
finally
|
||||
{
|
||||
System.Threading.Thread.CurrentThread.CurrentUICulture = savedCulture;
|
||||
}
|
||||
|
||||
UpdateActivityForLanguage(activityItems, "zh-cn");
|
||||
UpdateActivityForLanguage(activityItems, "zh-tw");
|
||||
UpdateActivityForLanguage(activityItems, "en-us");
|
||||
UpdateActivityForLanguage(activityItems, "ru-ru");
|
||||
MessageBox.Show("OK", Resources.Tips, MessageBoxButtons.OK);
|
||||
var activityLanguages = new[] { "zh-cn", "zh-tw", "en-us", "ru-ru" };
|
||||
for (var i = 0; i < activityLanguages.Length; i++)
|
||||
{
|
||||
var language = activityLanguages[i];
|
||||
ReportProgress(progress, 76 + i * 3, $"生成活动资源:{language}");
|
||||
UpdateActivityForLanguage(activityItems, language, projectResourcesPath, textMapData);
|
||||
}
|
||||
|
||||
var bannerLanguages = new[] { "zh-cn", "zh-tw", "en-us", "ru-ru" };
|
||||
for (var i = 0; i < bannerLanguages.Length; i++)
|
||||
{
|
||||
var language = bannerLanguages[i];
|
||||
ReportProgress(progress, 89 + i * 2, $"生成卡池标题:{language}");
|
||||
UpdateGachaResourceForLanguage(language, projectResourcesPath, textMapData);
|
||||
}
|
||||
|
||||
ReportProgress(progress, 100, "所有资源更新完成");
|
||||
}
|
||||
catch (Exception ex)
|
||||
finally
|
||||
{
|
||||
MessageBox.Show(ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
remoteSource?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateActivityForLanguage(IReadOnlyCollection<NewActivityItem> activityItems, string languageCode)
|
||||
private void SetUpdateBusy(bool busy)
|
||||
{
|
||||
TextMapData.LoadTextMapByLanguage(languageCode);
|
||||
if (IsDisposed || Disposing)
|
||||
return;
|
||||
|
||||
_updateInProgress = busy;
|
||||
BtnUpdateAllResources.Enabled = !busy;
|
||||
CmbResourceSource.Enabled = !busy;
|
||||
TxtProjectResRoot.Enabled = !busy;
|
||||
TxtGcResRoot.Enabled = !busy;
|
||||
TxtRemoteRepository.Enabled = !busy;
|
||||
TxtRemoteBranch.Enabled = !busy;
|
||||
TxtRemoteToken.Enabled = !busy;
|
||||
BtnGenerateToken.Enabled = !busy;
|
||||
PrgUpdateResources.Visible = busy;
|
||||
LblUpdateProgress.Visible = busy;
|
||||
if (busy)
|
||||
{
|
||||
PrgUpdateResources.Value = 0;
|
||||
LblUpdateProgress.Text = "准备中...";
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateResourceSourceControls();
|
||||
LblUpdateProgress.Text = string.Empty;
|
||||
}
|
||||
|
||||
UseWaitCursor = busy;
|
||||
var form = FindForm();
|
||||
if (form != null)
|
||||
form.UseWaitCursor = busy;
|
||||
}
|
||||
|
||||
private void UpdateProgressOnUi(UpdateProgressInfo progress)
|
||||
{
|
||||
if (IsDisposed || Disposing)
|
||||
return;
|
||||
|
||||
PrgUpdateResources.Value = Math.Max(0, Math.Min(100, progress.Value));
|
||||
LblUpdateProgress.Text = progress.Message;
|
||||
Logger.I(LogTag, progress.Message);
|
||||
}
|
||||
|
||||
private static void ReportProgress(IProgress<UpdateProgressInfo> progress, int value, string message)
|
||||
{
|
||||
progress?.Report(new UpdateProgressInfo(value, message));
|
||||
}
|
||||
|
||||
private void UpdateActivityForLanguage(IReadOnlyCollection<NewActivityItem> activityItems,
|
||||
string languageCode, string projectResourcesPath, TextMapData textMapData)
|
||||
{
|
||||
textMapData.LoadTextMapByLanguage(languageCode);
|
||||
|
||||
// 从 JSON 构建 activityId -> 翻译文本的映射
|
||||
var activityMap = new Dictionary<int, string>();
|
||||
foreach (var item in activityItems)
|
||||
activityMap[item.ActivityId] = TextMapData.GetText(item.NameTextMapHash);
|
||||
activityMap[item.ActivityId] = textMapData.GetText(item.NameTextMapHash);
|
||||
|
||||
var buffer = new StringBuilder();
|
||||
var processedIds = new HashSet<int>();
|
||||
@@ -228,53 +364,35 @@ namespace GrasscutterTools.Pages
|
||||
}
|
||||
}
|
||||
|
||||
var activityFilePath = Path.Combine(TxtProjectResRoot.Text, languageCode, "Activity.txt");
|
||||
var activityFilePath = Path.Combine(projectResourcesPath, languageCode, "Activity.txt");
|
||||
File.WriteAllText(activityFilePath, buffer.ToString(), Encoding.UTF8);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void UpdateGachaResourceForLanguage(string languageCode)
|
||||
private void UpdateGachaResourceForLanguage(string languageCode, string projectResourcesPath,
|
||||
TextMapData textMapData)
|
||||
{
|
||||
TextMapData.LoadTextMapByLanguage(languageCode);
|
||||
textMapData.LoadTextMapByLanguage(languageCode);
|
||||
|
||||
var titleBuffer = new StringBuilder();
|
||||
const string titlePattern = "UI_GACHA_SHOW_PANEL_([^_]+?)_TITLE";
|
||||
const string markPattern = "<[^>]+>";
|
||||
|
||||
foreach (var kv in TextMapData.ManualTextMap)
|
||||
foreach (var kv in textMapData.ManualTextMap)
|
||||
{
|
||||
var titleId = Regex.Match(kv.Value, titlePattern);
|
||||
if (!titleId.Success) continue;
|
||||
var text = TextMapData.TextMap[kv.Key];
|
||||
var text = textMapData.TextMap[kv.Key];
|
||||
titleBuffer.Append(titleId.Groups[1].Captures[0].Value)
|
||||
.Append(":")
|
||||
.AppendLine(Regex.Replace(text, markPattern, ""));
|
||||
}
|
||||
|
||||
var titleFilePath = Path.Combine(TxtProjectResRoot.Text, languageCode, "GachaBannerTitle.txt");
|
||||
var titleFilePath = Path.Combine(projectResourcesPath, languageCode, "GachaBannerTitle.txt");
|
||||
File.WriteAllText(titleFilePath, titleBuffer.ToString(), Encoding.UTF8);
|
||||
|
||||
}
|
||||
|
||||
private void BtnUpdateBannerTitles_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!CheckInputPaths()) return;
|
||||
|
||||
TextMapData ??= new TextMapData(TxtGcResRoot.Text);
|
||||
|
||||
UpdateGachaResourceForLanguage("zh-cn");
|
||||
UpdateGachaResourceForLanguage("zh-tw");
|
||||
UpdateGachaResourceForLanguage("en-us");
|
||||
UpdateGachaResourceForLanguage("ru-ru");
|
||||
MessageBox.Show("OK", Resources.Tips, MessageBoxButtons.OK);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user