Files
test/Assets/PerfectWorld/Scripts/Common/DataProcess/AFile.cs
T
2025-11-15 17:00:59 +07:00

56 lines
1.8 KiB
C#

using System;
using System.IO;
public class AFile
{
public static string CheckFOURCC(FileStream fs, ref long bytesRead)
{
var buffer = AAssit.ReadByArray(fs, ref bytesRead, 4, 0);
string FOURCC = System.Text.Encoding.ASCII.GetString(buffer);
Console.WriteLine($"File {fs.Name} FOURCC: {FOURCC}");
if (FOURCC != "MOXB" && FOURCC != "MOXT")
{
// not a valid FOURCC. No need to read it.
bytesRead = 0;
}
return FOURCC;
}
public static string NormalizePath(string path)
{
if (string.IsNullOrEmpty(path))
return path;
// Remove invalid characters from the path
char[] invalidChars = Path.GetInvalidPathChars();
foreach (char c in invalidChars)
{
path = path.Replace(c.ToString(), string.Empty);
}
// Additional handling for other potentially problematic characters
// that might not be included in GetInvalidPathChars but can cause issues
// path = path.Replace(":", string.Empty)
// .Replace("*", string.Empty)
// .Replace("?", string.Empty)
// .Replace("\"", string.Empty)
// .Replace("<", string.Empty)
// .Replace(">", string.Empty)
// .Replace("|", string.Empty);
path = path.Trim();
var items = path.Split('\\');
// use Path.Combine to normalize the path
path = Path.Combine(items);
// #if Unity windows
if (UnityEngine.Application.platform == UnityEngine.RuntimePlatform.WindowsEditor)
{
path = path.Replace("\\", "/");
}
return path;
}
}