2025-03-01 20:20:46 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.IO.Compression;
|
2025-03-01 21:50:19 +08:00
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
using System.Text;
|
2025-03-02 14:27:27 +08:00
|
|
|
|
using ICSharpCode.SharpZipLib.Zip;
|
2025-03-01 20:20:46 +08:00
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class RoTool : EditorWindow
|
|
|
|
|
|
{
|
|
|
|
|
|
[MenuItem("RO_Tool/[运行前准备] 合并Lua脚本到StreamingAssets目录!!", priority = 1)]
|
|
|
|
|
|
public static void MergeLuaAssets()
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("Merge Lua Files to Big File From Asset To Content Directory");
|
|
|
|
|
|
CompressFiles(Constants.LuaDir, "Assets/StreamingAssets/" + Constants.LuaDirMergeFile);
|
|
|
|
|
|
CompressFiles(Constants.LuaLogicDir, "Assets/StreamingAssets/" + Constants.LuaLogicDirMergeFile);
|
|
|
|
|
|
CompressFiles(Constants.LuaPbDir, "Assets/StreamingAssets/" + Constants.LuaPbDirMergeFile);
|
|
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[MenuItem("RO_Tool/[运行前准备] 合并配置文件到StreamingAssets目录!!", priority = 1)]
|
|
|
|
|
|
public static void MergeConfigAssets()
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("Merge Config Files to Big File From Asset To Content Directory");
|
|
|
|
|
|
CompressFiles(Constants.XmlConfig, "Assets/StreamingAssets/" + Constants.XmlConfigMergeFile);
|
|
|
|
|
|
CompressFiles(Constants.CsvConfig, "Assets/StreamingAssets/" + Constants.CsvConfigMergeFile);
|
|
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static HashSet<string> s_ValidExtMap = new HashSet<string>() { ".prefab", ".txt", ".xml", ".txt", ".lua", ".csv", ".ogg", ".wav", ".ttf", ".bytes", ".pb" };
|
|
|
|
|
|
private static List<string> getAllFilesPathEX(string path, string searchPattern = "*.*", SearchOption searchOption = SearchOption.AllDirectories)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<string> all = new List<string>();
|
|
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
|
|
{
|
|
|
|
|
|
return all;
|
|
|
|
|
|
}
|
|
|
|
|
|
string[] allFiles = Directory.GetFiles(path, searchPattern, searchOption);
|
|
|
|
|
|
for (int j = 0; j < allFiles.Length; ++j)
|
|
|
|
|
|
{
|
|
|
|
|
|
string fileName = allFiles[j];
|
|
|
|
|
|
string ext = Path.GetExtension(fileName);
|
|
|
|
|
|
if (string.IsNullOrEmpty(ext)) continue;
|
|
|
|
|
|
ext = ext.ToLower();
|
|
|
|
|
|
if (s_ValidExtMap.Contains(ext))
|
|
|
|
|
|
{
|
|
|
|
|
|
all.Add(fileName.Replace('\\', '/'));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return all;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 压缩文件
|
|
|
|
|
|
static private void CompressFiles(string inputDirectory, string zipPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
var files = getAllFilesPathEX(inputDirectory);
|
|
|
|
|
|
// 确保输出文件夹存在
|
|
|
|
|
|
string directory = Path.GetDirectoryName(zipPath);
|
|
|
|
|
|
if (!Directory.Exists(directory))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(directory);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个ZIP文件并开始写入
|
|
|
|
|
|
using (FileStream zipFile = new FileStream(zipPath, FileMode.Create))
|
|
|
|
|
|
{
|
2025-03-02 14:27:27 +08:00
|
|
|
|
using (ZipOutputStream zipStream = new ZipOutputStream(zipFile))
|
2025-03-01 20:20:46 +08:00
|
|
|
|
{
|
2025-03-02 14:27:27 +08:00
|
|
|
|
zipStream.SetLevel(6);
|
|
|
|
|
|
zipStream.Password = Constants.ZipPW;
|
2025-03-01 20:20:46 +08:00
|
|
|
|
foreach (var filePath in files)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (File.Exists(filePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取文件的名称(不带路径)
|
|
|
|
|
|
string fileName = Path.GetFileName(filePath);
|
2025-03-02 14:27:27 +08:00
|
|
|
|
FileInfo fileInfo = new FileInfo(filePath);
|
2025-03-01 21:50:19 +08:00
|
|
|
|
byte[] fileBytes = File.ReadAllBytes(filePath);
|
2025-03-02 14:27:27 +08:00
|
|
|
|
//byte[] aseFileBytes = CommonUtil.Encrypt(fileBytes);
|
2025-03-01 20:20:46 +08:00
|
|
|
|
Debug.Log($"Added file: {fileName} to the ZIP archive.");
|
2025-03-02 14:27:27 +08:00
|
|
|
|
// 将文件添加到ZIP档案
|
|
|
|
|
|
ZipEntry entry = new ZipEntry(fileName) {
|
|
|
|
|
|
//DateTime = fileInfo.LastWriteTime,
|
|
|
|
|
|
//AESKeySize = 128 // 使用 AES 256 位加密
|
|
|
|
|
|
};
|
|
|
|
|
|
zipStream.PutNextEntry(entry);
|
|
|
|
|
|
zipStream.Write(fileBytes, 0, fileBytes.Length);
|
|
|
|
|
|
zipStream.CloseEntry();
|
2025-03-01 20:20:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogWarning($"File does not exist: {filePath}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log($"Files successfully compressed into: {zipPath}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|