119 lines
3.6 KiB
C#
119 lines
3.6 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.IO;
|
||
|
|
using System.Linq;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
[Serializable]
|
||
|
|
public class FolderItem
|
||
|
|
{
|
||
|
|
public string folderName;
|
||
|
|
public int fileCount;
|
||
|
|
}
|
||
|
|
|
||
|
|
[Serializable]
|
||
|
|
public class Folders
|
||
|
|
{
|
||
|
|
public List<FolderItem> folders;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static class FolderChecker
|
||
|
|
{
|
||
|
|
private static Folders jsonFolders;
|
||
|
|
|
||
|
|
private static void ReadJson()
|
||
|
|
{
|
||
|
|
string jsonPath = Path.Combine(Application.streamingAssetsPath, "folderInfo.json");
|
||
|
|
string jsonContent = File.ReadAllText(jsonPath);
|
||
|
|
jsonFolders = JsonUtility.FromJson<Folders>(jsonContent);
|
||
|
|
Debug.Log($"待检测文件夹数目:{jsonFolders.folders.Count}");
|
||
|
|
}
|
||
|
|
|
||
|
|
public static bool CheckFolders()
|
||
|
|
{
|
||
|
|
if (Application.isEditor) return true;
|
||
|
|
// 读取Json
|
||
|
|
ReadJson();
|
||
|
|
// 获取根目录
|
||
|
|
string path = Directory.GetParent(Application.streamingAssetsPath).ToString();
|
||
|
|
path = Directory.GetParent(path).ToString();
|
||
|
|
// 检查文件夹是否完整
|
||
|
|
if (Directory.Exists(path))
|
||
|
|
{
|
||
|
|
List<string> folderList = Directory.GetDirectories(path).ToList();
|
||
|
|
List<string> floderNameList = new List<string>();
|
||
|
|
for (int i = 0; i < folderList.Count; i++)
|
||
|
|
{
|
||
|
|
string[] temp = folderList[i].Split('\\');
|
||
|
|
floderNameList.Add(temp[temp.Length - 1]);
|
||
|
|
}
|
||
|
|
|
||
|
|
for (int i = 0; i < jsonFolders.folders.Count; i++)
|
||
|
|
{
|
||
|
|
if (!floderNameList.Contains(jsonFolders.folders[i].folderName))
|
||
|
|
{
|
||
|
|
Debug.LogError($"不存在文件夹:{jsonFolders.folders[i].folderName}");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
Debug.LogError($"路径不存在:{path}");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public static bool CheckDllFileCount()
|
||
|
|
{
|
||
|
|
if (Application.isEditor) return true;
|
||
|
|
// 读取Json
|
||
|
|
ReadJson();
|
||
|
|
// 获取根目录
|
||
|
|
string path = Directory.GetParent(Application.streamingAssetsPath).ToString();
|
||
|
|
path = Directory.GetParent(path).ToString();
|
||
|
|
// 检查文件夹是否完整
|
||
|
|
if (Directory.Exists(path))
|
||
|
|
{
|
||
|
|
List<string> folderList = Directory.GetDirectories(path).ToList();
|
||
|
|
List<string> floderNameList = new List<string>();
|
||
|
|
for(int i = 0; i < folderList.Count; i++)
|
||
|
|
{
|
||
|
|
string[] temp = folderList[i].Split('\\');
|
||
|
|
floderNameList.Add(temp[temp.Length - 1]);
|
||
|
|
}
|
||
|
|
|
||
|
|
// 检查dll数量
|
||
|
|
for (int i = 0; i < jsonFolders.folders.Count; i++)
|
||
|
|
{
|
||
|
|
string folderName = jsonFolders.folders[i].folderName;
|
||
|
|
string folderPath = $"{path}\\{folderName}";
|
||
|
|
|
||
|
|
if (!floderNameList.Contains(folderName))
|
||
|
|
{
|
||
|
|
Debug.LogError($"不存在文件夹:{folderName}");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
int fileCount = Directory.GetFiles(folderPath, "*.dll", SearchOption.AllDirectories).Length;
|
||
|
|
if(fileCount != jsonFolders.folders[i].fileCount)
|
||
|
|
{
|
||
|
|
Debug.LogError($"{folderPath} dll文件缺失请检查");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
Debug.LogError($"路径不存在:{path}");
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|