VPet/VPet-Simulator.Tool/Program.cs

158 lines
6.4 KiB
C#
Raw Normal View History

2022-12-13 07:10:18 +00:00
using System;
2023-06-16 02:39:35 +00:00
using System.Collections.Generic;
using System.Drawing;
2022-12-13 07:10:18 +00:00
using System.IO;
2023-06-16 02:39:35 +00:00
using System.Linq;
2022-12-13 07:10:18 +00:00
using System.Security.Cryptography;
2023-06-16 02:39:35 +00:00
using System.Xml.Linq;
using VPet_Simulator.Core;
using static VPet_Simulator.Core.GraphCore;
2022-12-13 07:10:18 +00:00
namespace VPet_Simulator.Tool
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("VPet Simulator Tool");
start:
Console.WriteLine("请输入需要使用的功能编号");
Console.WriteLine("1. 精简动画相同图片");
switch (Console.ReadLine())
{
case "1":
2023-05-27 10:37:15 +00:00
Animation();
break;
2023-07-17 15:38:06 +00:00
//case "2":
// FontPetNew();
// break;
2022-12-13 07:10:18 +00:00
default:
Console.WriteLine("暂无该功能");
goto start;
}
}
/// <summary>
/// 将图片重命名并转换成 名字_序号_持续时间 格式
/// </summary>
static void Animation()
{
Console.WriteLine("请输入每张图片的持续时间 (单位: 毫秒)");
string timestr = Console.ReadLine();
2023-05-27 10:37:15 +00:00
if (!int.TryParse(timestr, out int time))
2023-02-22 05:37:23 +00:00
{
time = 125;
}
2023-05-27 10:37:15 +00:00
while (true)
2022-12-13 07:10:18 +00:00
{
2023-05-27 10:37:15 +00:00
Console.WriteLine("请输入图片位置");
DirectoryInfo directoryInfo = new DirectoryInfo(Console.ReadLine());
int id = 0;
int rpt = 1;
string hash = null;
FileInfo lastf = null;
foreach (FileInfo fileInfo in directoryInfo.GetFiles())
2022-12-13 07:10:18 +00:00
{
2023-05-27 10:37:15 +00:00
if (lastf == null)
{
lastf = fileInfo;
hash = GetFileHash(fileInfo);
continue;
}
string filehash = GetFileHash(fileInfo);
if (hash.Equals(filehash))
{
//这个文件和上一个文件的hash值相同这个上个文件
lastf.Delete();
lastf = fileInfo;
rpt++;
continue;
}
hash = filehash;
2023-06-16 02:39:35 +00:00
lastf.MoveTo(Path.Combine(directoryInfo.FullName, $"{GetFileName(lastf)}_{id++:D3}_{rpt * time}.png"));
2023-05-27 10:37:15 +00:00
rpt = 1;
2022-12-13 07:10:18 +00:00
lastf = fileInfo;
}
2023-06-16 02:39:35 +00:00
lastf.MoveTo(Path.Combine(directoryInfo.FullName, $"{GetFileName(lastf)}_{id++:D3}_{rpt * time}.png"));
2023-05-27 10:37:15 +00:00
Console.WriteLine("图片处理已完成");
2022-12-13 07:10:18 +00:00
}
}
2023-06-16 02:39:35 +00:00
2023-07-17 15:38:06 +00:00
//static void FontPetNew()
//{
// Console.WriteLine("请输入储存位置");
// DirectoryInfo directoryInfo = new DirectoryInfo(Console.ReadLine());
2023-06-16 02:39:35 +00:00
2023-07-17 15:38:06 +00:00
// var elist = Properties.Resources.laenum.Replace(" ", "").Replace("/// <summary>", "")
// .Replace("/// </summary>", "").Replace("/// ", "").Replace("\r", "").Replace("\n\n", "\n")
// .Replace("\n\n", "\n").Replace("\n\n", "\n").Split('\n').ToList();
// elist.RemoveAll(x => x.EndsWith(","));
// for (int i = 0; i < elist.Count; i++)
// {
// var paths = GraphTypeValue[i].Split('_');
// DirectoryInfo nowpath = directoryInfo;
// foreach (var path in paths)
// {
// nowpath = nowpath.CreateSubdirectory(path);
// }
// foreach (string v in Enum.GetNames(typeof(GameSave.ModeType)))
// {
// using (Bitmap image = new Bitmap(500, 500))
// {
// using (Graphics g = Graphics.FromImage(image))
// {
// var strs = elist[i].Split(' ');
// g.DrawString(strs[0], new Font("胡晓波男神体2.0", 66, FontStyle.Bold), new SolidBrush(Color.DarkSlateBlue), 10, 100);
// g.DrawString(strs[0], new Font("胡晓波男神体2.0", 64), new SolidBrush(Color.AliceBlue), 15, 100);
// for (int j = 1; j < strs.Length - 1; j++)
// {
// g.DrawString(strs[j], new Font("胡晓波萌萌体", 50, FontStyle.Bold), new SolidBrush(Color.LightGray), 10, 150 + 50 * j);
// g.DrawString(strs[j], new Font("胡晓波萌萌体", 48, FontStyle.Bold), new SolidBrush(Color.Gray), 15, 150 + 50 * j);
// }
// g.DrawString(v, new Font("胡晓波润圆体35", 50, FontStyle.Bold), new SolidBrush(Color.DeepSkyBlue), 10, 350);
// g.DrawString(v, new Font("胡晓波润圆体35", 48, FontStyle.Bold), new SolidBrush(Color.SkyBlue), 15, 350);
// int len = 2000;
// var last = strs.Last();
// if(last == "S")
// {
// len = 250;
// }
// else if (last == "M")
// {
// len = 1000;
// }
// image.Save(nowpath.CreateSubdirectory(v).FullName + $"\\{paths[0]}_{len}.png");
// }
// }
// }
2023-06-16 02:39:35 +00:00
2023-07-17 15:38:06 +00:00
// }
//}
2022-12-13 07:10:18 +00:00
public static string GetFileHash(FileInfo fileInfo)
{
//创建一个哈希算法对象
using (HashAlgorithm hash = HashAlgorithm.Create())
{
using (FileStream file = fileInfo.OpenRead())
{
//哈希算法根据文本得到哈希码的字节数组
return BitConverter.ToString(hash.ComputeHash(file));
}
}
}
2023-06-16 02:39:35 +00:00
public static string GetFileName(FileInfo fileInfo)
{
var strs = fileInfo.Name.Split('_', '-');
if (strs.Length == 1)
{
strs = fileInfo.Name.Replace("00", "_").Split('_');
}
if (strs.Length == 1)
{
return fileInfo.Directory.Name;
}
return strs[0];
}
2022-12-13 07:10:18 +00:00
}
2023-06-16 02:39:35 +00:00
2022-12-13 07:10:18 +00:00
}