2024-05-26 03:10:21 +00:00
|
|
|
|
using System;
|
2024-07-21 15:18:44 +00:00
|
|
|
|
using System.IO;
|
2024-05-26 03:10:21 +00:00
|
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.utils;
|
|
|
|
|
|
2024-05-26 11:09:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>ResUtils</para>
|
|
|
|
|
/// <para>资源文件工具类</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class ResUtils
|
2024-05-26 03:10:21 +00:00
|
|
|
|
{
|
2024-05-26 11:09:43 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>The suffix that the game engine adds to the resource file while the game is running</para>
|
|
|
|
|
/// <para>游戏运行时,游戏引擎为资源文件添加的后缀</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const string Suffix = ".remap";
|
|
|
|
|
|
2024-07-21 15:18:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Gets the location of its own dll</para>
|
|
|
|
|
/// <para>获取自身dll的存放位置</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string? GetSelfDllFolder()
|
|
|
|
|
{
|
|
|
|
|
var currentDirectory = Environment.CurrentDirectory;
|
2024-07-23 15:03:03 +00:00
|
|
|
|
var osEnum = Config.GetOs(true);
|
|
|
|
|
if (osEnum == Config.OsEnum.Editor)
|
2024-07-21 15:18:44 +00:00
|
|
|
|
{
|
|
|
|
|
return Path.Join(currentDirectory, ".godot", "mono", "temp", "bin", "Debug");
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 15:03:03 +00:00
|
|
|
|
if (osEnum == Config.OsEnum.Windows)
|
2024-07-21 15:18:44 +00:00
|
|
|
|
{
|
|
|
|
|
return Path.Join(currentDirectory, "data_" + Config.SolutionName + "_windows_x86_64");
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 15:03:03 +00:00
|
|
|
|
if (osEnum == Config.OsEnum.Linux)
|
2024-07-21 15:18:44 +00:00
|
|
|
|
{
|
|
|
|
|
return Path.Join(currentDirectory, "data_" + Config.SolutionName + "_linuxbsd_x86_64");
|
|
|
|
|
}
|
2024-07-23 15:03:03 +00:00
|
|
|
|
|
2024-07-21 15:18:44 +00:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-26 03:10:21 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>The game returns the res directory with a.remap suffix at runtime, causing an error while loading the resource</para>
|
|
|
|
|
/// <para>游戏在运行时返回res目录后带有.remap后缀,导致加载资源时出错</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-05-26 11:09:43 +00:00
|
|
|
|
public static string GetEditorResPath(string path)
|
2024-05-26 03:10:21 +00:00
|
|
|
|
{
|
2024-05-26 11:09:43 +00:00
|
|
|
|
if (Config.IsEditor())
|
|
|
|
|
{
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var index = path.LastIndexOf(Suffix, StringComparison.Ordinal);
|
2024-05-26 03:10:21 +00:00
|
|
|
|
return index > -1 ? path[..index] : path;
|
|
|
|
|
}
|
2024-05-26 11:09:43 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Gets the runtime path of the resource file</para>
|
|
|
|
|
/// <para>获取资源文件运行时路径</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static string GetRunTimeResPath(string path)
|
|
|
|
|
{
|
|
|
|
|
if (Config.IsEditor())
|
|
|
|
|
{
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Determine whether the path is a file path
|
|
|
|
|
//判断路径是否为文件路径
|
|
|
|
|
var symbolIndex = path.LastIndexOf('.');
|
|
|
|
|
if (symbolIndex > -1)
|
|
|
|
|
{
|
|
|
|
|
//Found the file symbol
|
|
|
|
|
//找到了文件符号
|
|
|
|
|
var index = path.LastIndexOf(Suffix, StringComparison.Ordinal);
|
|
|
|
|
return index > -1 ? path : path + Suffix;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-26 03:10:21 +00:00
|
|
|
|
}
|