Skip to content

Commit

Permalink
Update FilesSignature.cs (#1087)
Browse files Browse the repository at this point in the history
做了以下几点改动:
1.使用 Path.Combine() 确保路径的正确性,使其在各系统下均能兼容
2.修复了代码中的一些变量命名和拼写错误
3.对文件处理部分做了优化
  • Loading branch information
xiezheng-XD authored Aug 31, 2023
1 parent 4d01bb2 commit 0d68213
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions General/Src/FilesSignature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,54 @@ namespace XLua
{
public class FilesSignature
{
static void useage()
static void usage()
{
Console.WriteLine("FilesSignature from_path to_path");
}

static void doSignature(string from, string to, SHA1 sha, RSACryptoServiceProvider rsa)
{
if(!Directory.Exists(to))
if (!Directory.Exists(to))
{
Directory.CreateDirectory(to);
}
foreach(var filename in Directory.GetFiles(from, "*.lua"))
foreach (var filename in Directory.GetFiles(from, "*.lua"))
{
byte[] filecontent = File.ReadAllBytes(filename);
byte[] sig = rsa.SignData(filecontent, sha);
FileStream fs = new FileStream(to + "/" + Path.GetFileName(filename), FileMode.Create);
fs.Write(sig, 0, sig.Length);
fs.Write(filecontent, 0, filecontent.Length);
fs.Close();
string sigFilePath = Path.Combine(to, Path.GetFileName(filename));
using (FileStream fs = new FileStream(sigFilePath, FileMode.Create))
{
fs.Write(sig, 0, sig.Length);
fs.Write(filecontent, 0, filecontent.Length);
fs.Flush();
}
}
foreach(var dir in Directory.GetDirectories(from))
foreach (var dir in Directory.GetDirectories(from))
{

doSignature(dir, to + "/" + new DirectoryInfo(dir).Name, sha, rsa);
string newDir = Path.Combine(to, new DirectoryInfo(dir).Name);
doSignature(dir, newDir, sha, rsa);
}
}

public static void Main(string[] args)
{
if (!File.Exists("key_ras"))
if (!File.Exists("key_rsa"))
{
Console.WriteLine("no key_ras!");
Console.WriteLine("No key_rsa file found!");
return;
}

if (args.Length != 2)
{
useage();
usage();
return;
}

SHA1 sha = new SHA1CryptoServiceProvider();
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(File.ReadAllText("key_ras"));
rsa.FromXmlString(File.ReadAllText("key_rsa"));
doSignature(args[0], args[1], sha, rsa);
}
}
}
}

0 comments on commit 0d68213

Please sign in to comment.