/// <summary> /// 初始化文件系统 /// </summary> public static void InitFileSystem() { //var appDataRootPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); //if (string.IsNullOrWhiteSpace(appDataRootPath)) //{ // // 需要测试 macOS 和 linux 上 Environment.SpecialFolder.ApplicationData 返回的目录值 // // 之前在 android 上测试过 Environment.GetFolderPath 有些枚举值返回的是空字符串 比如StartMenu // throw new ArgumentNullException(nameof(appDataRootPath)); //} //appDataRootPath = Path.Combine(appDataRootPath, BuildConfig.APPLICATION_ID); var appDataRootPath = #if NET35 WinFormsApplication.StartupPath; #else AppContext.BaseDirectory; #endif var appDataPath = Path.Combine(appDataRootPath, AppDataDirName); var cachePath = Path.Combine(appDataRootPath, CacheDirName); IOPath.DirCreateByNotExists(appDataPath); IOPath.DirCreateByNotExists(cachePath); IOPath.InitFileSystem(GetAppDataDirectory, GetCacheDirectory); string GetAppDataDirectory() => appDataPath; string GetCacheDirectory() => cachePath; }
public void OneTimeSetUp() { // TODO: Add code here that is run before // all tests in the assembly are run if (!DIInit) { ModelValidatorProvider.Init(); DI.Init(ConfigureServices); var path = AppContext.BaseDirectory; var path1 = Path.Combine(path, "AppData"); IOPath.DirCreateByNotExists(path1); var path2 = Path.Combine(path, "Cache"); IOPath.DirCreateByNotExists(path2); string GetAppDataDirectory() => path1; string GetCacheDirectory() => path2; IOPath.InitFileSystem(GetAppDataDirectory, GetCacheDirectory); } }