67 lines
2.2 KiB
C#
67 lines
2.2 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Security.Cryptography;
|
|
using System.Text.Json;
|
|
using System.Collections.Generic;
|
|
|
|
class Program
|
|
{
|
|
static string buildPath = "Build"; // Unity 빌드 폴더 (예: Build/)
|
|
static string outputJsonFile = "file_list.json"; // 생성할 JSON 파일
|
|
|
|
static void Main()
|
|
{
|
|
Console.WriteLine("🔍 Unity 빌드 파일 목록 생성 중...");
|
|
|
|
if (!Directory.Exists(buildPath))
|
|
{
|
|
Console.WriteLine($"❌ 빌드 폴더가 존재하지 않습니다: {buildPath}");
|
|
return;
|
|
}
|
|
|
|
Dictionary<string, string> fileHashes = new Dictionary<string, string>();
|
|
|
|
foreach (string filePath in Directory.GetFiles(buildPath, "*", SearchOption.AllDirectories))
|
|
{
|
|
string relativePath = Path.GetRelativePath(buildPath, filePath).Replace("\\", "/");
|
|
string hash = GetFileHash(filePath);
|
|
fileHashes[relativePath] = hash;
|
|
}
|
|
|
|
|
|
|
|
// 🔒 모든 해시 값을 알파벳 순으로 정렬하고 이어붙인 뒤 전체 SHA256 계산
|
|
string combinedHashes = string.Join("", new SortedDictionary<string, string>(fileHashes).Values);
|
|
string versionID = GetVersionID(combinedHashes);
|
|
|
|
var jsonObject = new
|
|
{
|
|
VersionID = versionID,
|
|
Files = fileHashes
|
|
};
|
|
|
|
string jsonString = JsonSerializer.Serialize(jsonObject, new JsonSerializerOptions { WriteIndented = true });
|
|
|
|
File.WriteAllText(Path.Combine(".", outputJsonFile), jsonString);
|
|
}
|
|
|
|
static string GetFileHash(string filePath)
|
|
{
|
|
using (var sha256 = SHA256.Create())
|
|
using (var stream = File.OpenRead(filePath))
|
|
{
|
|
byte[] hashBytes = sha256.ComputeHash(stream);
|
|
return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
|
|
}
|
|
}
|
|
static string GetVersionID(string input)
|
|
{
|
|
using (var sha256 = SHA256.Create())
|
|
{
|
|
byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
|
|
byte[] hashBytes = sha256.ComputeHash(inputBytes);
|
|
return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
|
|
}
|
|
}
|
|
}
|