using System; using System.IO; namespace BITKit { public class PathHelper { static string appDataPath=_appDataPath; [ExcuteOnAwake] public static void Init() { if (string.IsNullOrEmpty(appDataPath)) { appDataPath = Path.Combine(Environment.CurrentDirectory, BITApp.AppName); } BIT4Log.Log($"配置文件路径:{appDataPath}"); DirectoryInfo directoryInfo = new(appDataPath); directoryInfo.Create(); } public static string GetFolderPath(params string[] paths) { var path = GetPath(paths); if (path is not null) { DirectoryInfo directoryInfo = new(path); directoryInfo.Create(); Directory.CreateDirectory(path); return path; } return GetPath(paths); } public static string GetFilePath(params string[] paths) { var path = GetPath(paths); var dictionaryPath = Path.GetDirectoryName(path); Directory.CreateDirectory(dictionaryPath); if (File.Exists(path) is false) { using (var fs = File.Create(path)) { fs.Close(); fs.Dispose(); } } return path; } public static string GetTempFilePath(string fileName = null) { var path = GetFilePath("Temps", fileName is null ? Guid.NewGuid().ToString():fileName); return path; } public static string GetPath(params string[] paths) { return Path.Combine(appDataPath, Path.Combine(paths)); } static string _appDataPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), BITApp.AppName); } }