DiskCacheCommon.cs
1 using Ryujinx.Common.Logging; 2 using System.IO; 3 4 namespace Ryujinx.Graphics.Gpu.Shader.DiskCache 5 { 6 /// <summary> 7 /// Common disk cache utility methods. 8 /// </summary> 9 static class DiskCacheCommon 10 { 11 /// <summary> 12 /// Opens a file for read or write. 13 /// </summary> 14 /// <param name="basePath">Base path of the file (should not include the file name)</param> 15 /// <param name="fileName">Name of the file</param> 16 /// <param name="writable">Indicates if the file will be read or written</param> 17 /// <returns>File stream</returns> 18 public static FileStream OpenFile(string basePath, string fileName, bool writable) 19 { 20 string fullPath = Path.Combine(basePath, fileName); 21 22 FileMode mode; 23 FileAccess access; 24 25 if (writable) 26 { 27 mode = FileMode.OpenOrCreate; 28 access = FileAccess.ReadWrite; 29 } 30 else 31 { 32 mode = FileMode.Open; 33 access = FileAccess.Read; 34 } 35 36 try 37 { 38 return new FileStream(fullPath, mode, access, FileShare.Read); 39 } 40 catch (IOException ioException) 41 { 42 Logger.Error?.Print(LogClass.Gpu, $"Could not access file \"{fullPath}\". {ioException.Message}"); 43 44 throw new DiskCacheLoadException(DiskCacheLoadResult.NoAccess); 45 } 46 } 47 48 /// <summary> 49 /// Gets the compression algorithm that should be used when writing the disk cache. 50 /// </summary> 51 /// <returns>Compression algorithm</returns> 52 public static CompressionAlgorithm GetCompressionAlgorithm() 53 { 54 return CompressionAlgorithm.Brotli; 55 } 56 } 57 }