using Ryujinx.Common.Logging;
using System.IO;
namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
{
///
/// Common disk cache utility methods.
///
static class DiskCacheCommon
{
///
/// Opens a file for read or write.
///
/// Base path of the file (should not include the file name)
/// Name of the file
/// Indicates if the file will be read or written
/// File stream
public static FileStream OpenFile(string basePath, string fileName, bool writable)
{
string fullPath = Path.Combine(basePath, fileName);
FileMode mode;
FileAccess access;
if (writable)
{
mode = FileMode.OpenOrCreate;
access = FileAccess.ReadWrite;
}
else
{
mode = FileMode.Open;
access = FileAccess.Read;
}
try
{
return new FileStream(fullPath, mode, access, FileShare.Read);
}
catch (IOException ioException)
{
Logger.Error?.Print(LogClass.Gpu, $"Could not access file \"{fullPath}\". {ioException.Message}");
throw new DiskCacheLoadException(DiskCacheLoadResult.NoAccess);
}
}
///
/// Gets the compression algorithm that should be used when writing the disk cache.
///
/// Compression algorithm
public static CompressionAlgorithm GetCompressionAlgorithm()
{
return CompressionAlgorithm.Brotli;
}
}
}