修复引用相关的bug,优化界面

This commit is contained in:
ShakeFlower 2024-11-16 23:58:14 +08:00
parent 5ee67609b7
commit 73e7fea888
13 changed files with 145 additions and 89 deletions

View File

@ -21,13 +21,13 @@
<Button Name ="BrowseSourceFolderButton" FontSize ="16" Content="浏览" Canvas.Left="680" Canvas.Top="10" Width="40" Command="{Binding SelectSourceCommand}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<Button x:Name ="BrowseDestFolderButton" FontSize ="16" Content="浏览" Canvas.Left="680" Canvas.Top="47" Width="40" Command="{Binding SelectDestCommand}" HorizontalAlignment="Center" VerticalAlignment="Top"/>
<Button FontSize ="16" Content="开始迁移" Canvas.Left="30" Canvas.Top="127" Width="140" Command="{Binding MigrateCommand}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<Button FontSize ="16" Content="开始迁移" Canvas.Left="30" Canvas.Top="127" Width="140" Command="{Binding MigrateCommand}" IsEnabled= "{Binding IsAvailable}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<CheckBox Name ="MigrateConfig" Content="迁移配置表格" Height="26" Canvas.Left="426" Canvas.Top="134" Width="100" IsChecked="{Binding MigrateServerTable}"/>
<Button FontSize ="16" Content="查看帮助" Canvas.Left="223" Canvas.Top="127" Width="140" Command="{Binding MigrateCommand}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<Button FontSize ="16" Content="查看帮助" Canvas.Left="223" Canvas.Top="127" Width="140" Command="{Binding HelpCommand}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
<ListBox Height="90" Canvas.Left="30" Canvas.Top="230" Width="690" ItemsSource="{Binding ErrorMessages}" HorizontalAlignment="Center" VerticalAlignment="Top">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Text}" Foreground="{Binding Color}" />
<TextBlock Text="{Binding Text}" Foreground="{Binding Color}" TextWrapping="Wrap"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

View File

@ -14,6 +14,7 @@ namespace H5MotaUpdate.ViewModels
private string? _versionString;
private string? SourceProjectDirectory, DestProjectDirectroy;
private bool _migrateServerTable;
private bool _isAvailable;
public string? SourceRootDirectory
{
@ -55,6 +56,15 @@ namespace H5MotaUpdate.ViewModels
}
}
public bool IsAvailable
{
get => _isAvailable;
set
{
_isAvailable = value;
OnPropertyChanged();
}
}
public ObservableCollection<ColoredString> ErrorMessages => ErrorLogger.ErrorMessages;
public ICommand SelectSourceCommand { get; set; }
@ -64,13 +74,6 @@ namespace H5MotaUpdate.ViewModels
public MainViewModel()
{
ErrorLogger.LogError("111", "red");
ErrorLogger.LogError("222", "");
ErrorLogger.LogError("222", "");
ErrorLogger.LogError("222", "");
ErrorLogger.LogError("222", "");
ErrorLogger.LogError("222", "");
ErrorLogger.LogError("222", "");
SourceRootDirectory = "请选择包含要翻新的旧塔的文件夹";
DestRootDirectory = "请选择一个包含新的2.10.3样板的文件夹";
VersionString = "-";
@ -79,6 +82,7 @@ namespace H5MotaUpdate.ViewModels
MigrateCommand = new RelayCommand(StartMigrate);
HelpCommand = new RelayCommand(FileUtils.ShowHelp);
MigrateServerTable = false;
IsAvailable = true;
}
private void SelectSourceRootFolder()
@ -116,6 +120,7 @@ namespace H5MotaUpdate.ViewModels
if (!VersionUtils.IsValidVersion(VersionString))
{
MessageBox.Show("版本号格式不合法!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("版本号格式不合法!", "red");
return false;
}
return true;
@ -129,10 +134,14 @@ namespace H5MotaUpdate.ViewModels
public void StartMigrate()
{
if (!CheckValid()) return;
IsAvailable = false;
Version ver;
Version.TryParse(VersionString, out ver);
#region
ErrorLogger.Clear();
// 每次开始迁移,清空之前报错信息
#region
// 从libs/core.js中读取塔的默认长宽若不为13需要写入新样板的core.js中
int width, height;
string sourceCoreJSPath = Path.Combine(SourceRootDirectory, "libs/core.js"),
@ -143,7 +152,7 @@ namespace H5MotaUpdate.ViewModels
{
StringUtils.WriteMapWidth(destCoreJSPath, width, height);
}
#endregion
#endregion
DataJSMigrator dataJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
EnemysJSMigrator enemysJSMigrator = new(SourceProjectDirectory, DestProjectDirectroy, ver);
@ -166,7 +175,10 @@ namespace H5MotaUpdate.ViewModels
ServerTableMigrator serverTableJSMigrator = new(SourceRootDirectory, DestRootDirectory, ver);
serverTableJSMigrator.Migrate();
}
string endMsg = "迁移完成,请仔细核对结果。";
MessageBox.Show(endMsg);
ErrorLogger.LogError(endMsg);
IsAvailable = true;
}
public event PropertyChangedEventHandler? PropertyChanged;

View File

@ -12,8 +12,8 @@ namespace H5MotaUpdate.ViewModels
DATANAME = "data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d";
public DataJSMigrator(string oldProjectDirectory, string newProjectDirectory, Version ver)
{
sourcePath = System.IO.Path.Combine(oldProjectDirectory, FILENAME);
destPath = System.IO.Path.Combine(newProjectDirectory, FILENAME);
sourcePath = Path.Combine(oldProjectDirectory, FILENAME);
destPath = Path.Combine(newProjectDirectory, FILENAME);
this.version = ver;
}
@ -37,11 +37,11 @@ namespace H5MotaUpdate.ViewModels
newJsContent.Append(jsonObject.ToString());
File.WriteAllText(destPath, newJsContent.ToString());
}
MessageBox.Show("迁移project/" + FILENAME + "文件完成。");
ErrorLogger.LogError("迁移project/" + FILENAME + "文件完成。");
}
catch (Exception e)
{
MessageBox.Show("迁移project/" + FILENAME + $"过程中出现错误: {e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移project/" + FILENAME + $"过程中出现错误: {e.Message}", "red");
}
}
@ -61,12 +61,16 @@ namespace H5MotaUpdate.ViewModels
JArray tilesetArr = (JArray)mainData["tilesets"];
if (tilesetArr != null && tilesetArr.Count > 0) // 2.4.2(?)之前不存在main.tilesets
{
foreach (JToken tileset in tilesetArr)
for (int i = 0; i < tilesetArr.Count; i++)
{
string tilesetStr = tileset.ToString();
if (tilesetStr.Contains('.'))
JToken tileset = tilesetArr[i];
if (tileset.Type == JTokenType.String)
{
tilesetStr += ".png";
string tilesetStr = (string)tileset;
if (!tilesetStr.Contains('.'))
{
tilesetArr[i] = tilesetStr + ".png";
}
}
}
}
@ -160,12 +164,11 @@ namespace H5MotaUpdate.ViewModels
{
heroToolsData = new JObject();
}
StringUtils.MergeJObjects(heroToolsData, heroKeysData);
heroItemData["tools"] = StringUtils.MergeJObjects(heroToolsData, heroKeysData);
}
heroItemData.Remove("keys");
#region
#region
// 转换全局商店shop的格式
JArray shopArr = (JArray)firstData["shops"];
for (int i = 0; i < shopArr.Count; i++)
@ -187,11 +190,9 @@ namespace H5MotaUpdate.ViewModels
shopNeed = shop["need"].ToString(),
shopText = shop["text"].ToString(),
shopId = shop["id"].ToString(),
flagName_Time = "flag:" + shopId + "_times", // 新设的购买次数变量flag:xxx
flagName_Price = "flag:" + shopId + "_price"; // 新设的价格变量flag:xxx
string priceStr = shopNeed.Replace("times", flagName_Time); //用新变量名取代times之后的商店价格字符串
flagName_Time = "flag:" + shopId + "_times"; // 新设的购买次数变量flag:xxx
string priceStr = shopNeed.Replace("times", flagName_Time); //商店价格字符串用新变量名取代times
shop["text"] = StringUtils.ReplaceInBetweenCurlyBraces(shopText, "times", flagName_Time);
shop["text"] = StringUtils.ReplaceInBetweenCurlyBraces(shopText, "need", flagName_Price);
shop["disablePreview"] = false;
if (use == "experience")
@ -206,7 +207,7 @@ namespace H5MotaUpdate.ViewModels
string? choiceNeed = null;
if (choice.ContainsKey("need"))
{
choiceNeed = choice["need"].ToString().Replace("times", flagName_Time);
choiceNeed = choice["need"].ToString().Replace("times", flagName_Time); // 单个选项的价格字符串
requirement = "status:" + use + ">=" + choiceNeed;
}
else
@ -216,15 +217,14 @@ namespace H5MotaUpdate.ViewModels
choice["need"] = requirement; // 单个选项的使用条件
JArray newAction = new JArray();
JObject setPrice = StringUtils.getAddValueJson(flagName_Price, choiceNeed != null ? choiceNeed : priceStr, "="),
deductMoney = StringUtils.getAddValueJson("status:" + use, flagName_Price, "-="),
JObject
deductMoney = StringUtils.getAddValueJson("status:" + use, choiceNeed != null ? choiceNeed : priceStr, "-="),
addTime = StringUtils.getAddValueJson(flagName_Time, "1", "+=");
newAction.Add(setPrice);
newAction.Add(deductMoney);
newAction.Add(addTime);
string oldEffect = choice["effect"].ToString();
var newEffectJArray = StringUtils.doEffect(oldEffect);
JArray newEffectJArray = StringUtils.doEffect(oldEffect);
newAction.Merge(newEffectJArray);
choice["action"] = newAction; //单个选项使用时执行的事件
}

View File

@ -47,11 +47,11 @@ namespace H5MotaUpdate.ViewModels
newJsContent.Append(jsonObject.ToString());
File.WriteAllText(destPath, newJsContent.ToString());
}
MessageBox.Show("迁移project/" + FILENAME + "文件完成");
ErrorLogger.LogError("迁移project/" + FILENAME + "文件完成");
}
catch (Exception e)
{
MessageBox.Show("迁移project/" + FILENAME + $"过程中出现错误: {e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移project/" + FILENAME + $"过程中出现错误: {e.Message}", "red");
}
}

View File

@ -37,11 +37,11 @@ namespace H5MotaUpdate.ViewModels
this.mapsIndexArray = mapsIndexArray;
MigrateFloors();
}
MessageBox.Show("迁移project/" + FILENAME + "文件夹完成。");
ErrorLogger.LogError("迁移project/" + FILENAME + "文件夹完成。");
}
catch (Exception e)
{
MessageBox.Show("迁移project/" + FILENAME + $"文件夹过程中出现错误: {e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移project/" + FILENAME + $"文件夹过程中出现错误: {e.Message}", "red");
}
}
@ -79,7 +79,7 @@ namespace H5MotaUpdate.ViewModels
}
catch (Exception e)
{
MessageBox.Show("迁移楼层文件" + System.IO.Path.GetFileName(sourceFilePath) + $"时出现错误: {e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移楼层文件" + System.IO.Path.GetFileName(sourceFilePath) + $"时出现错误: {e.Message}", "red");
}
}

View File

@ -42,11 +42,11 @@ namespace H5MotaUpdate.ViewModels
newJsContent.Append(jsonObject.ToString());
File.WriteAllText(destPath, newJsContent.ToString());
}
MessageBox.Show("迁移project/" + FILENAME + "文件完成");
ErrorLogger.LogError("迁移project/" + FILENAME + "文件完成");
}
catch (Exception e)
{
MessageBox.Show("迁移project/" + FILENAME + $"过程中出现错误: {e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移project/" + FILENAME + $"过程中出现错误: {e.Message}", "red");
}
}

View File

@ -40,11 +40,11 @@ namespace H5MotaUpdate.ViewModels
newJsContent.Append(jsonObject.ToString());
File.WriteAllText(destPath, newJsContent.ToString());
}
MessageBox.Show("迁移project/" + FILENAME + "文件完成。");
ErrorLogger.LogError("迁移project/" + FILENAME + "文件完成。");
}
catch (Exception e)
{
MessageBox.Show("迁移project/" + FILENAME + $"过程中出现错误: {e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移project/" + FILENAME + $"过程中出现错误: {e.Message}", "red");
}
}

View File

@ -42,11 +42,11 @@ namespace H5MotaUpdate.ViewModels
newJsContent.Append(jsonObject.ToString());
File.WriteAllText(destPath, newJsContent.ToString());
}
MessageBox.Show("迁移project/" + FILENAME + "文件完成。");
ErrorLogger.LogError("迁移project/" + FILENAME + "文件完成。");
}
catch (Exception e)
{
MessageBox.Show("迁移project/" + FILENAME + $"过程中出现错误: {e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移project/" + FILENAME + $"过程中出现错误: {e.Message}", "red");
}
}
@ -126,7 +126,7 @@ namespace H5MotaUpdate.ViewModels
}
if (i == 9999)
{
MessageBox.Show("警告Maps.js中存在过多元素", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("警告Maps.js中存在过多元素可能引起一些未知问题。", "red");
}
}
@ -146,24 +146,31 @@ namespace H5MotaUpdate.ViewModels
foreach (JProperty prop in jsonObject.Properties())
{
JObject propObj = (JObject)prop.Value;
if (prop.Value is JObject propObj)
{
JToken noPass = propObj["noPass"];
JToken noPass = propObj["noPass"];
if (noPass != null && noPass.ToString() == "True")
{
propObj["canPass"] = false;
}
if (noPass != null && noPass.ToString() == "False")
{
propObj["canPass"] = true;
}
propObj.Remove("noPass");
if (noPass != null && noPass.Value<bool>())
{
propObj["canPass"] = false;
}
else if (noPass != null && !noPass.Value<bool>())
{
propObj["canPass"] = true;
}
// 原先id存在的icons直接查找替换
string iconId = propObj["id"].ToString();
if (dictionary.ContainsKey(iconId))
{
propObj = StringUtils.MergeJObjects(propObj, dictionary[iconId]);
// 移除 noPass 属性
propObj.Remove("noPass");
string iconId = propObj["id"]?.ToString();
if (!string.IsNullOrEmpty(iconId) && dictionary.ContainsKey(iconId))
{
prop.Value = StringUtils.MergeJObjects(propObj, dictionary[iconId]);
}
else
{
prop.Value = propObj;
}
}
}

View File

@ -30,11 +30,11 @@ namespace H5MotaUpdate.ViewModels
{
Convert();
}
MessageBox.Show("迁移素材文件完成。");
ErrorLogger.LogError("迁移素材文件完成。");
}
catch (Exception e)
{
MessageBox.Show("迁移素材文件过程中出现错误: " + $"{e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移素材文件过程中出现错误: " + $"{e.Message}", "red");
}
}
@ -48,11 +48,11 @@ namespace H5MotaUpdate.ViewModels
string sourcePath = Path.Combine(oldProjectDirectory, folderName),
destPath = Path.Combine(newProjectDirectory, folderName);
FileUtils.CopyFolderContents(sourcePath, destPath);
MessageBox.Show("project/" + folderName + "文件夹迁移完成");
ErrorLogger.LogError("project/" + folderName + "文件夹迁移完成");
}
catch (Exception ex)
{
MessageBox.Show("project/" + folderName + $"文件夹迁移失败,原因:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("project/" + folderName + $"文件夹迁移失败,原因:{ex.Message}", "red");
}
}
}
@ -101,7 +101,7 @@ namespace H5MotaUpdate.ViewModels
}
catch (Exception ex)
{
MessageBox.Show($"素材文件夹迁移出错,原因:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError($"素材文件夹迁移出错,原因:{ex.Message}", "red");
}
}
@ -112,11 +112,11 @@ namespace H5MotaUpdate.ViewModels
string inputDirectory = Path.Combine(oldProjectDirectory, "animates"),
outputDirectory = Path.Combine(newProjectDirectory, "animates");
FileUtils.CopyFolderContents(inputDirectory, outputDirectory);
MessageBox.Show("project/animates文件夹迁移完成");
ErrorLogger.LogError("project/animates文件夹迁移完成");
}
catch (Exception ex)
{
MessageBox.Show($"project/animates文件夹迁移出错原因:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError($"project/animates文件夹迁移出错原因:{ex.Message}", "red");
}
}
@ -151,6 +151,7 @@ namespace H5MotaUpdate.ViewModels
int height = image.Height;
if (height < 1120)
{
ErrorLogger.LogError("警告原塔的icons.png长度不足请对照最新样板使用PS工具补齐数字键和Alt图标等。", "red");
MessageBox.Show("警告原塔的icons.png长度不足请对照最新样板使用PS工具补齐数字键和Alt图标等。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
@ -173,11 +174,11 @@ namespace H5MotaUpdate.ViewModels
File.Copy(filePath, Path.Combine(newProjectDirectory, "tilesets/" + fileName), true);
}
}
MessageBox.Show("project/images文件夹迁移完成");
ErrorLogger.LogError("project/images文件夹迁移完成");
}
catch (Exception ex)
{
MessageBox.Show($"project/images文件夹迁移出错原因:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError($"project/images文件夹迁移出错原因:{ex.Message}", "red");
}
}
@ -200,11 +201,11 @@ namespace H5MotaUpdate.ViewModels
File.Copy(filePath, Path.Combine(newProjectDirectory, "sounds/" + fileName), true);
}
}
MessageBox.Show("project/sounds文件夹迁移完成");
ErrorLogger.LogError("project/sounds文件夹迁移完成");
}
catch (Exception ex)
{
MessageBox.Show($"project/sounds文件夹迁移出错原因:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError($"project/sounds文件夹迁移出错原因:{ex.Message}", "red");
}
}
}

View File

@ -17,11 +17,11 @@
try
{
MigrateDirect();
MessageBox.Show("迁移" + FILENAME + "文件夹完成。");
ErrorLogger.LogError("迁移" + FILENAME + "文件夹完成。");
}
catch (Exception e)
{
MessageBox.Show("迁移" + FILENAME + $"过程中出现错误: {e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移" + FILENAME + $"过程中出现错误: {e.Message}", "red");
}
}

View File

@ -20,7 +20,7 @@ namespace H5MotaUpdate.ViewModels
{
private static ObservableCollection<ColoredString> _errorMessages = new ObservableCollection<ColoredString>();
public static ObservableCollection<ColoredString> ErrorMessages { get { return _errorMessages; } }
public static ObservableCollection<ColoredString> ErrorMessages => _errorMessages;
public static void LogError(string error, string color)
{
@ -37,6 +37,11 @@ namespace H5MotaUpdate.ViewModels
}
public static void LogError(string error)
{
ErrorMessages.Add(new ColoredString(error, Brushes.Black));
}
public static void Clear()
{
_errorMessages.Clear();

View File

@ -1,4 +1,5 @@
using System.IO;
using System.Diagnostics;
using System.IO;
namespace H5MotaUpdate.ViewModels
{
@ -13,13 +14,17 @@ namespace H5MotaUpdate.ViewModels
{
if (!Directory.Exists(folderPath))
{
MessageBox.Show(folderName + "文件夹不存在,请检查", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
string errMsg = folderName + "文件夹不存在,请检查";
MessageBox.Show(errMsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError(errMsg, "red");
return false;
}
}
catch (Exception e)
catch
{
MessageBox.Show(folderName + $"文件夹不存在,请检查,错误:{e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
string errMsg = folderName + "文件夹不存在,请检查";
MessageBox.Show(errMsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError(errMsg, "red");
return false;
}
return true;
@ -46,12 +51,16 @@ namespace H5MotaUpdate.ViewModels
try { Directory.CreateDirectory(folderDirectory); }
catch (Exception e)
{
MessageBox.Show($"错误:{e.Message},目标文件夹不存在" + folderName + "子文件夹,且创建失败,请检查", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
string errMsg = $"错误:{e.Message},目标文件夹不存在" + folderName + "子文件夹,且创建失败,请检查";
MessageBox.Show(errMsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError(errMsg, "red");
return false;
}
if (!Directory.Exists(folderDirectory))
{
MessageBox.Show("目标文件夹不存在" + folderName + "子文件夹,且创建失败,请检查", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
string errMsg = "目标文件夹不存在" + folderName + "子文件夹,且创建失败,请检查";
MessageBox.Show(errMsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError(errMsg, "red");
return false;
}
return true;
@ -72,7 +81,7 @@ namespace H5MotaUpdate.ViewModels
}
catch (Exception e)
{
MessageBox.Show("迁移" + file + $"过程中出现错误:{e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移" + file + $"过程中出现错误:{e.Message}", "red");
}
}
}
@ -92,7 +101,7 @@ namespace H5MotaUpdate.ViewModels
}
catch (Exception e)
{
MessageBox.Show("迁移" + file + $"过程中出现错误:{e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移" + file + $"过程中出现错误:{e.Message}", "red");
}
}
@ -106,7 +115,7 @@ namespace H5MotaUpdate.ViewModels
}
catch (Exception e)
{
MessageBox.Show("迁移" + dir + $"过程中出现错误:{e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移" + dir + $"过程中出现错误:{e.Message}", "red");
}
}
}
@ -123,16 +132,16 @@ namespace H5MotaUpdate.ViewModels
if (!File.Exists(SourcePath))
{
MessageBox.Show("源文件夹不存在" + fileName + "子文件,请检查", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("源文件夹不存在" + fileName + "子文件,请检查", "red");
}
else
{
System.IO.File.Copy(SourcePath, DestPath, true);
File.Copy(SourcePath, DestPath, true);
}
}
catch (Exception e)
{
MessageBox.Show("迁移" + fileName + $"文件出现错误:{e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("迁移" + fileName + $"文件出现错误:{e.Message}", "red");
}
}
@ -141,7 +150,28 @@ namespace H5MotaUpdate.ViewModels
/// </summary>
public static void ShowHelp()
{
try
{
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
string readMePath = Path.Combine(appDirectory, "readme.txt");
if (File.Exists(readMePath))
{
Process.Start(new ProcessStartInfo
{
FileName = readMePath,
UseShellExecute = true
});
}
else
{
MessageBox.Show("readme.txt 不存在", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch (Exception ex)
{
MessageBox.Show($"无法打开readme.txt发生了错误: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
}

View File

@ -31,7 +31,7 @@ namespace H5MotaUpdate.ViewModels
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show("从" + path + "中读取JSON时出错:" + $"{e.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
ErrorLogger.LogError("从" + path + "中读取JSON时出错:" + $"{e.Message}", "red");
throw;
}
}
@ -191,6 +191,7 @@ namespace H5MotaUpdate.ViewModels
{
width = 13;
height = 13;
ErrorLogger.LogError("错误未能从源文件夹的libs/core.js中读取到地图长宽数据", "red");
}
return (width, height);
}
@ -214,7 +215,7 @@ namespace H5MotaUpdate.ViewModels
}
catch
{
ErrorLogger.LogError("错误修改目标文件夹libs/core.js中的地图长宽数据失败", "red");
}
}
}