连接服务器version
This commit is contained in:
@@ -181,19 +181,6 @@ namespace TcgEngine
|
||||
downloadCompleted = true;
|
||||
UpdateProgress(1f);
|
||||
UpdateStatus("资源解压完成!");
|
||||
|
||||
// 打印解压后的文件夹位置
|
||||
if (ResourceDownloader.Get() != null)
|
||||
{
|
||||
ResourceDownloader.Get().LogResourcePaths();
|
||||
|
||||
// 另外也可以直接打印路径
|
||||
string spritesPath = ResourceDownloader.Get().GetSpritesDirectoryPath();
|
||||
Debug.Log($"[ResourceInitializer] 资源解压到: {spritesPath}");
|
||||
|
||||
// 在macOS上,可以直接用这个命令在终端中打开文件夹
|
||||
Debug.Log($"[ResourceInitializer] 打开文件夹命令: open \"{spritesPath}\"");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -17,19 +17,11 @@ namespace TcgEngine
|
||||
[Header("Download Settings")]
|
||||
public string serverUrl = "https://cardcdn.ambigrat.com";
|
||||
public string resourcesEndpoint = "/test/{version}.zip";
|
||||
public string versionEndpoint = "/api/version";
|
||||
public string versionEndpoint = "/version";
|
||||
|
||||
[Header("URL Pattern Options")]
|
||||
[Tooltip("支持的占位符: {version} - 版本号")]
|
||||
public bool useVersionInFilename = true;
|
||||
[Tooltip("如果启用,会先检查版本化文件是否存在")]
|
||||
public bool validateVersionedUrl = false;
|
||||
[Tooltip("调试模式:当版本接口失败时,使用固定版本号")]
|
||||
public bool debugMode = true;
|
||||
[Tooltip("调试模式下使用的固定版本号")]
|
||||
public string debugVersion = "0.0.1";
|
||||
[Tooltip("调试模式下使用的固定MD5值")]
|
||||
public string debugMd5 = "ceb24758054d6dcf1e23ddb41811a525";
|
||||
[Tooltip("检查版本化文件是否存在")]
|
||||
public bool validateVersionedUrl = true;
|
||||
private string currentVersion = "0.0.0";
|
||||
private string currentMd5 = "";
|
||||
private string targetVersion = "0.0.1";
|
||||
@@ -87,18 +79,6 @@ namespace TcgEngine
|
||||
var serverVersionData = await GetServerVersionData();
|
||||
if (serverVersionData == null || string.IsNullOrEmpty(serverVersionData.version))
|
||||
{
|
||||
Debug.LogWarning("Failed to get server version");
|
||||
|
||||
// 调试模式:版本接口失败时使用固定版本号
|
||||
if (debugMode)
|
||||
{
|
||||
Debug.Log($"Debug mode enabled: using fixed version {debugVersion} and MD5 {debugMd5}");
|
||||
targetVersion = debugVersion;
|
||||
targetMd5 = debugMd5;
|
||||
|
||||
return await CheckVersionAndMd5();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -112,16 +92,6 @@ namespace TcgEngine
|
||||
{
|
||||
Debug.LogError($"Error checking for updates: {e.Message}");
|
||||
|
||||
// 调试模式:出现异常时也尝试使用固定版本
|
||||
if (debugMode)
|
||||
{
|
||||
Debug.Log($"Debug mode: attempting to use version {debugVersion} despite error");
|
||||
targetVersion = debugVersion;
|
||||
targetMd5 = debugMd5;
|
||||
|
||||
return await CheckVersionAndMd5();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -152,20 +122,13 @@ namespace TcgEngine
|
||||
return false;
|
||||
}
|
||||
|
||||
Debug.Log($"版本匹配,开始检查MD5校验...");
|
||||
Debug.Log($"当前版本: {currentVersion}");
|
||||
Debug.Log($"目标版本: {targetVersion}");
|
||||
Debug.Log($"保存的MD5: {currentMd5}");
|
||||
Debug.Log($"目标MD5: {targetMd5}");
|
||||
Debug.Log($"版本匹配,开始检查MD5校验... 当前版本: {currentVersion} 目标版本: {targetVersion} 当前MD5: {currentMd5} 目标MD5: {targetMd5}");
|
||||
|
||||
string localMd5 = await CalculateDirectoryMd5(spritesPath);
|
||||
|
||||
if (localMd5 != targetMd5)
|
||||
{
|
||||
Debug.LogWarning($"🚨 MD5校验失败!");
|
||||
Debug.LogWarning($"本地计算MD5: {localMd5}");
|
||||
Debug.LogWarning($"期望的MD5: {targetMd5}");
|
||||
Debug.Log("正在删除损坏的文件并重新下载...");
|
||||
Debug.Log("MD5校验失败,正在删除损坏的文件并重新下载...");
|
||||
|
||||
// 删除损坏的文件
|
||||
if (Directory.Exists(spritesPath))
|
||||
@@ -176,8 +139,7 @@ namespace TcgEngine
|
||||
return true; // 需要重新下载
|
||||
}
|
||||
|
||||
Debug.Log($"✅ MD5校验通过: {localMd5}");
|
||||
Debug.Log("文件完整性验证成功,无需下载");
|
||||
Debug.Log($"✅ MD5校验通过");
|
||||
return false; // 无需下载
|
||||
}
|
||||
|
||||
@@ -195,25 +157,9 @@ namespace TcgEngine
|
||||
if (files.Length == 0)
|
||||
return "";
|
||||
|
||||
Debug.Log($"=== 开始计算目录MD5 ===");
|
||||
Debug.Log($"目录路径: {directoryPath}");
|
||||
Debug.Log($"文件数量: {files.Length}");
|
||||
|
||||
// 按路径排序确保一致性
|
||||
Array.Sort(files);
|
||||
|
||||
// 打印前几个文件作为示例
|
||||
Debug.Log("文件列表示例:");
|
||||
for (int i = 0; i < Math.Min(5, files.Length); i++)
|
||||
{
|
||||
string relativePath = files[i].Substring(directoryPath.Length + 1).Replace('\\', '/');
|
||||
Debug.Log($" [{i+1}] {relativePath}");
|
||||
}
|
||||
if (files.Length > 5)
|
||||
{
|
||||
Debug.Log($" ... 还有 {files.Length - 5} 个文件");
|
||||
}
|
||||
|
||||
using (var md5 = System.Security.Cryptography.MD5.Create())
|
||||
{
|
||||
foreach (string file in files)
|
||||
@@ -238,12 +184,6 @@ namespace TcgEngine
|
||||
md5.TransformFinalBlock(new byte[0], 0, 0);
|
||||
string result = BitConverter.ToString(md5.Hash).Replace("-", "").ToLowerInvariant();
|
||||
|
||||
Debug.Log($"=== MD5计算完成 ===");
|
||||
Debug.Log($"本地计算的MD5: {result}");
|
||||
Debug.Log($"目标MD5: {targetMd5}");
|
||||
Debug.Log($"MD5匹配: {(result == targetMd5 ? "✅ 是" : "❌ 否")}");
|
||||
Debug.Log($"===================");
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -261,19 +201,13 @@ namespace TcgEngine
|
||||
{
|
||||
string targetFileName;
|
||||
|
||||
if (!useVersionInFilename)
|
||||
if (string.IsNullOrEmpty(version))
|
||||
{
|
||||
// 不使用版本化文件名时,统一使用"sprites"
|
||||
targetFileName = "sprites";
|
||||
}
|
||||
else if (string.IsNullOrEmpty(version))
|
||||
{
|
||||
// 如果版本为空,使用调试版本
|
||||
targetFileName = debugVersion;
|
||||
Debug.LogError("Version is null");
|
||||
return "0.0.0";
|
||||
}
|
||||
else
|
||||
{
|
||||
// 使用实际版本号
|
||||
targetFileName = version;
|
||||
}
|
||||
|
||||
@@ -327,17 +261,8 @@ namespace TcgEngine
|
||||
/// </summary>
|
||||
private async Task<ResourceVersionResponse> GetServerVersionData()
|
||||
{
|
||||
// 从NetworkData获取游戏服务器地址
|
||||
string gameServerUrl = NetworkData.Get().api_url;
|
||||
if (string.IsNullOrEmpty(gameServerUrl))
|
||||
{
|
||||
Debug.LogError("Failed to get game server URL from NetworkData");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 构建完整的版本检查URL
|
||||
string protocol = NetworkData.Get().api_https ? "https://" : "http://";
|
||||
string url = protocol + gameServerUrl + versionEndpoint;
|
||||
string url = "http://192.168.1.99:8080" + versionEndpoint;
|
||||
Debug.Log($"Version check URL: {url}");
|
||||
using (UnityWebRequest request = UnityWebRequest.Get(url))
|
||||
{
|
||||
@@ -584,79 +509,6 @@ namespace TcgEngine
|
||||
return currentVersion;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定版本的下载URL(用于调试)
|
||||
/// </summary>
|
||||
public string GetDownloadUrlForVersion(string version)
|
||||
{
|
||||
return BuildVersionedDownloadUrl(version);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前目标版本的下载URL
|
||||
/// </summary>
|
||||
public string GetCurrentDownloadUrl()
|
||||
{
|
||||
return BuildVersionedDownloadUrl(targetVersion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本地Sprites目录的完整路径(用于调试)
|
||||
/// </summary>
|
||||
public string GetSpritesDirectoryPath()
|
||||
{
|
||||
return spritesPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 手动计算并打印当前Sprites目录的MD5
|
||||
/// </summary>
|
||||
public async void CalculateAndLogCurrentMd5()
|
||||
{
|
||||
Debug.Log("=== 手动计算当前Sprites目录MD5 ===");
|
||||
if (!Directory.Exists(spritesPath))
|
||||
{
|
||||
Debug.LogWarning("Sprites目录不存在!");
|
||||
return;
|
||||
}
|
||||
|
||||
string calculatedMd5 = await CalculateDirectoryMd5(spritesPath);
|
||||
Debug.Log($"手动计算结果: {calculatedMd5}");
|
||||
Debug.Log($"当前保存的MD5: {currentMd5}");
|
||||
Debug.Log($"调试MD5: {debugMd5}");
|
||||
Debug.Log("================================");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打印本地资源路径信息
|
||||
/// </summary>
|
||||
public void LogResourcePaths()
|
||||
{
|
||||
Debug.Log($"=== Resource Paths ===");
|
||||
Debug.Log($"persistentDataPath: {persistentDataPath}");
|
||||
Debug.Log($"Sprites Directory: {spritesPath}");
|
||||
Debug.Log($"Directory Exists: {Directory.Exists(spritesPath)}");
|
||||
|
||||
if (Directory.Exists(spritesPath))
|
||||
{
|
||||
var files = Directory.GetFiles(spritesPath, "*", SearchOption.AllDirectories);
|
||||
Debug.Log($"Total files in Sprites: {files.Length}");
|
||||
|
||||
// 显示前10个文件作为示例
|
||||
for (int i = 0; i < Math.Min(10, files.Length); i++)
|
||||
{
|
||||
string relativePath = files[i].Substring(spritesPath.Length + 1);
|
||||
Debug.Log($" {relativePath}");
|
||||
}
|
||||
|
||||
if (files.Length > 10)
|
||||
{
|
||||
Debug.Log($" ... and {files.Length - 10} more files");
|
||||
}
|
||||
}
|
||||
Debug.Log($"======================");
|
||||
}
|
||||
|
||||
public static ResourceDownloader Get()
|
||||
{
|
||||
if (instance == null)
|
||||
|
||||
Reference in New Issue
Block a user