fix:读取版本号时优先读取this.__VERSION__; 可手动修改版本号; 重排布局; 为防止炸样板, icons.js不再进行迁移
This commit is contained in:
parent
3f3d29a734
commit
a96b7ad67e
@ -10,26 +10,75 @@
|
||||
<Window.DataContext>
|
||||
<vm:MainViewModel></vm:MainViewModel>
|
||||
</Window.DataContext>
|
||||
<Canvas>
|
||||
<TextBlock FontSize ="16" Height="20" Canvas.Left="10" Text="旧塔文件夹" Canvas.Top="15" Width="100" HorizontalAlignment="Center" VerticalAlignment="Top"/>
|
||||
<TextBlock FontSize ="16" Height="20" Canvas.Left="10" Text="新样板文件夹" Canvas.Top="50" Width="100" HorizontalAlignment="Center" VerticalAlignment="Top"/>
|
||||
<TextBlock FontSize ="16" Height="20" Canvas.Left="10" Text="旧塔版本号" Canvas.Top="85" Width="100" HorizontalAlignment="Center" VerticalAlignment="Top"/>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid Grid.Row="0" Margin="0,0,0,10">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" FontSize ="16"
|
||||
Text="旧塔文件夹" />
|
||||
<TextBlock Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" FontSize ="14"
|
||||
Width="500" TextWrapping ="Wrap"
|
||||
Name ="InputFolderPath" Text="{Binding SourceRootDirectory}"/>
|
||||
<Button Grid.Row="0" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" Padding="5,2,5,2" FontSize ="16"
|
||||
Name ="BrowseSourceFolderButton" Content="浏览" Command="{Binding SelectSourceCommand}"/>
|
||||
|
||||
<TextBlock Name ="InputFolderPath" FontSize ="14" Height="40" Canvas.Left="140" Canvas.Top="15" Width="500" TextWrapping ="Wrap" Text="{Binding SourceRootDirectory}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
|
||||
<TextBlock Name ="OutputFolderPath" FontSize ="14" Height="40" Canvas.Left="140" Canvas.Top="50" Width="500" TextWrapping ="Wrap" Text="{Binding DestRootDirectory}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
|
||||
<TextBlock FontSize ="16" Height="20" Canvas.Left="140" Text="{Binding VersionString}" Canvas.Top="85" Width="Auto" HorizontalAlignment="Left" VerticalAlignment="Center"/>
|
||||
<TextBlock Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10"
|
||||
Text="新样板文件夹" FontSize ="16" />
|
||||
<TextBlock Grid.Row="1" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" FontSize ="14"
|
||||
Width="500" TextWrapping ="Wrap"
|
||||
Name ="OutputFolderPath" Text="{Binding DestRootDirectory}" />
|
||||
<Button Grid.Row="1" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10" Padding="5,2,5,2" FontSize ="16"
|
||||
x:Name ="BrowseDestFolderButton" Content="浏览" Command="{Binding SelectDestCommand}"/>
|
||||
|
||||
<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}" 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 HelpCommand}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
|
||||
<ListBox Height="90" Canvas.Left="30" Canvas.Top="230" Width="690" ItemsSource="{Binding ErrorMessages}" HorizontalAlignment="Center" VerticalAlignment="Top">
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="15,10,0,10"
|
||||
Text="旧塔版本号" FontSize ="16"/>
|
||||
<Grid Grid.Row="2" Grid.Column="1">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="40,10,40,10" FontSize ="16"
|
||||
Text="{Binding VersionString}" Width="Auto" />
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Width="80" Height="25" Margin="40,10,10,10" FontSize ="16"
|
||||
Text="{Binding VersionString, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="1" Margin="0,0,0,30">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="50,10,0,10" Padding="10,5,10,5" FontSize ="16"
|
||||
Content="开始迁移" Command="{Binding MigrateCommand}" IsEnabled= "{Binding IsAvailable}" />
|
||||
<Button Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="50,10,0,10" Padding="10,5,10,5" FontSize ="16"
|
||||
Content="查看帮助" Command="{Binding HelpCommand}"/>
|
||||
<CheckBox Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="50,10,0,10" FontSize ="14"
|
||||
Name ="MigrateConfig" Content="迁移配置表格" IsChecked="{Binding MigrateServerTable}"/>
|
||||
</Grid>
|
||||
|
||||
<ListBox Grid.Row="2" Width="700" Height ="140" ItemsSource="{Binding ErrorMessages}" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Text}" Foreground="{Binding Color}" TextWrapping="Wrap"/>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
</Canvas>
|
||||
</Grid>
|
||||
|
||||
</Window>
|
||||
|
@ -6,7 +6,6 @@ using System.Windows.Input;
|
||||
|
||||
namespace H5MotaUpdate.ViewModels
|
||||
{
|
||||
//silverCoin->Wand
|
||||
class MainViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private string? _sourceRootDirectory;
|
||||
@ -85,6 +84,9 @@ namespace H5MotaUpdate.ViewModels
|
||||
IsAvailable = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择要翻新的旧塔的文件夹,会自动读取旧塔的版本号
|
||||
/// </summary>
|
||||
private void SelectSourceRootFolder()
|
||||
{
|
||||
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
|
||||
@ -97,6 +99,9 @@ namespace H5MotaUpdate.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 选择新样板文件夹
|
||||
/// </summary>
|
||||
public void SelectDestRootFolder()
|
||||
{
|
||||
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
|
||||
|
@ -143,20 +143,26 @@ namespace H5MotaUpdate.ViewModels
|
||||
foreach (string filePath in files)
|
||||
{
|
||||
string fileName = Path.GetFileName(filePath);
|
||||
if (fileName == "icons.png" && version < new Version(2, 5, 4)) //检查icons长度
|
||||
// 由于屡次导致工程爆炸,icons.png就不复制了
|
||||
if (fileName == "icons.png")
|
||||
{
|
||||
using (Bitmap image = new Bitmap(filePath))
|
||||
{
|
||||
int width = image.Width;
|
||||
int height = image.Height;
|
||||
if (height < 1120)
|
||||
{
|
||||
ErrorLogger.LogError("警告:原塔的icons.png长度不足!请对照最新样板使用PS工具补齐数字键和Alt图标等。", "red");
|
||||
MessageBox.Show("警告:原塔的icons.png长度不足!请对照最新样板使用PS工具补齐数字键和Alt图标等。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
//if (fileName == "icons.png" && version < new Version(2, 5, 4)) //检查icons长度
|
||||
//{
|
||||
// using (Bitmap image = new Bitmap(filePath))
|
||||
// {
|
||||
// int width = image.Width;
|
||||
// int height = image.Height;
|
||||
// if (height < 1120)
|
||||
// {
|
||||
// ErrorLogger.LogError("警告:原塔的icons.png长度不足!请对照最新样板使用PS工具补齐数字键和Alt图标等。", "red");
|
||||
// MessageBox.Show("警告:原塔的icons.png长度不足!请对照最新样板使用PS工具补齐数字键和Alt图标等。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
if (imagesList.Contains(fileName))
|
||||
{
|
||||
File.Copy(filePath, Path.Combine(newProjectDirectory, "images/" + fileName), true);
|
||||
|
@ -16,30 +16,54 @@ namespace H5MotaUpdate.ViewModels
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从给定路径的旧塔文件夹中读取版本号
|
||||
/// </summary>
|
||||
/// <param name="folderPath"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetVersion(string? folderPath)
|
||||
{
|
||||
if (folderPath == null) return "文件夹路径不合法";
|
||||
|
||||
string filePath = Path.Combine(folderPath, "main.js");
|
||||
string version;
|
||||
|
||||
if (!File.Exists(filePath)) return "给定文件夹未找到文件main.js";
|
||||
|
||||
string fileContent;
|
||||
try
|
||||
{
|
||||
if (!File.Exists(filePath)) return "给定文件夹未找到文件main.js";
|
||||
|
||||
string fileContent = File.ReadAllText(filePath);
|
||||
|
||||
Regex versionRegex = new Regex(@"this\.version\s*=\s*['""](\d+(\.\d+)+)['""];");
|
||||
Match match = versionRegex.Match(fileContent);
|
||||
|
||||
if (!match.Success) return "文件 main.js中未找到版本号!";
|
||||
version = match.Groups[1].Value;
|
||||
if (!IsValidVersion(version)) return "文件 main.js中未找到格式合法的版本号!";
|
||||
fileContent = File.ReadAllText(filePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "读取版本号失败,原因: " + ex.Message;
|
||||
return "读取文件内容失败,原因: " + ex.Message;
|
||||
}
|
||||
return version;
|
||||
|
||||
string version = null;
|
||||
|
||||
// 优先匹配 this.__VERSION__ = "...";
|
||||
Regex specialVersionRegex = new Regex(
|
||||
@"this\s*\.\s*__VERSION__\s*=\s*['""](\d+(\.\d+)+)['""]\s*;?");
|
||||
Match specialMatch = specialVersionRegex.Match(fileContent);
|
||||
if (specialMatch.Success)
|
||||
{
|
||||
version = specialMatch.Groups[1].Value;
|
||||
if (IsValidVersion(version))
|
||||
return version;
|
||||
}
|
||||
|
||||
// 回退到原来的方式:this.version = "x.x.x"
|
||||
Regex normalVersionRegex = new Regex(@"this\.version\s*=\s*['""](\d+(\.\d+)+)['""];?");
|
||||
Match normalVersionMatch = normalVersionRegex.Match(fileContent);
|
||||
|
||||
if (normalVersionMatch.Success)
|
||||
{
|
||||
version = normalVersionMatch.Groups[1].Value;
|
||||
if (IsValidVersion(version))
|
||||
return version;
|
||||
}
|
||||
|
||||
return "文件 main.js中未找到格式合法的版本号!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user