修复引用相关的bug,优化界面
This commit is contained in:
1 parent
5ee67609b7
commit
73e7fea888
13 files changed
+145
-89
No files matched your search
@@ -0,0 +1,50 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using Brush = System.Windows.Media.Brush;
|
||||
using Brushes = System.Windows.Media.Brushes;
|
||||
public class ColoredString
|
||||
{
|
||||
public string Text { get; set; }
|
||||
public Brush Color { get; set; }
|
||||
|
||||
public ColoredString(string text, Brush color)
|
||||
{
|
||||
Text = text;
|
||||
Color = color;
|
||||
}
|
||||
}
|
||||
|
||||
namespace H5MotaUpdate.ViewModels
|
||||
{
|
||||
internal static class ErrorLogger
|
||||
{
|
||||
private static ObservableCollection<ColoredString> _errorMessages = new ObservableCollection<ColoredString>();
|
||||
|
||||
public static ObservableCollection<ColoredString> ErrorMessages => _errorMessages;
|
||||
|
||||
public static void LogError(string error, string color)
|
||||
{
|
||||
switch (color)
|
||||
{
|
||||
case "red":
|
||||
ErrorMessages.Add(new ColoredString(error, Brushes.Red));
|
||||
break;
|
||||
case "black":
|
||||
default:
|
||||
ErrorMessages.Add(new ColoredString(error, Brushes.Black));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void LogError(string error)
|
||||
{
|
||||
ErrorMessages.Add(new ColoredString(error, Brushes.Black));
|
||||
}
|
||||
|
||||
public static void Clear()
|
||||
{
|
||||
_errorMessages.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user