This commit is contained in:
2026-06-15 18:18:16 +08:00
parent 97c9fba14e
commit 2b9f134e5f
4164 changed files with 386922 additions and 79 deletions

View File

@@ -0,0 +1,87 @@
#define _ENABLE_LOGGING
using System;
using System.IO;
namespace Best.HTTP.Shared.PlatformSupport.FileSystem
{
public sealed class DefaultIOService : IIOService
{
public Stream CreateFileStream(string path, FileStreamModes mode)
{
#if ENABLE_LOGGING
if (HTTPManager.Logger.IsDiagnostic)
HTTPManager.Logger.Verbose(nameof(DefaultIOService), $"{nameof(CreateFileStream)}('{path}', {mode})");
#endif
switch (mode)
{
case FileStreamModes.Create:
return new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
case FileStreamModes.OpenRead:
return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read /*, 64 * 1024, FileOptions.SequentialScan*/);
case FileStreamModes.OpenReadWrite:
return new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
case FileStreamModes.Append:
return new FileStream(path, FileMode.Append);
}
throw new NotImplementedException($"{nameof(DefaultIOService)}.{nameof(CreateFileStream)} - '{mode}' not implemented!");
}
public void DirectoryCreate(string path)
{
#if ENABLE_LOGGING
if (HTTPManager.Logger.IsDiagnostic)
HTTPManager.Logger.Verbose(nameof(DefaultIOService), $"{nameof(DirectoryCreate)}('{path}')");
#endif
Directory.CreateDirectory(path);
}
public void DirectoryDelete(string path) => Directory.Delete(path, true);
public bool DirectoryExists(string path)
{
bool exists = Directory.Exists(path);
#if ENABLE_LOGGING
if (HTTPManager.Logger.IsDiagnostic)
HTTPManager.Logger.Verbose(nameof(DefaultIOService), $"{nameof(DirectoryExists)}('{path}', {exists})");
#endif
return exists;
}
public string[] GetFiles(string path)
{
var files = Directory.GetFiles(path);
#if ENABLE_LOGGING
if (HTTPManager.Logger.IsDiagnostic)
HTTPManager.Logger.Verbose(nameof(DefaultIOService), $"{nameof(GetFiles)}('{path}', {files?.Length})");
#endif
return files;
}
public void FileDelete(string path)
{
#if ENABLE_LOGGING
if (HTTPManager.Logger.IsDiagnostic)
HTTPManager.Logger.Verbose(nameof(DefaultIOService), $"{nameof(FileDelete)}('{path}')");
#endif
File.Delete(path);
}
public bool FileExists(string path)
{
bool exists = File.Exists(path);
#if ENABLE_LOGGING
if (HTTPManager.Logger.IsDiagnostic)
HTTPManager.Logger.Verbose(nameof(DefaultIOService), $"{nameof(FileExists)}('{path}', {exists})");
#endif
return exists;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 70d8cd7c804fca64ca518e3bb0210fb0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,74 @@
using System;
using System.IO;
namespace Best.HTTP.Shared.PlatformSupport.FileSystem
{
/// <summary>
/// These are the different modes that the plugin want's to use a filestream.
/// </summary>
public enum FileStreamModes
{
/// <summary>
/// Create a new file.
/// </summary>
Create,
/// <summary>
/// Open an existing file for reading.
/// </summary>
OpenRead,
/// <summary>
/// Open or create a file for read and write.
/// </summary>
OpenReadWrite,
/// <summary>
/// Open an existing file for writing to the end.
/// </summary>
Append
}
/// <summary>
/// Interface for file-system abstraction.
/// </summary>
public interface IIOService
{
/// <summary>
/// Create a directory for the given path.
/// </summary>
void DirectoryCreate(string path);
/// <summary>
/// Return true if the directory exists for the given path.
/// </summary>
bool DirectoryExists(string path);
/// <summary>
/// Delete the directory.
/// </summary>
void DirectoryDelete(string path);
/// <summary>
/// Return with the file names for the given path.
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
string[] GetFiles(string path);
/// <summary>
/// Delete the file for the given path.
/// </summary>
void FileDelete(string path);
/// <summary>
/// Return true if the file exists on the given path.
/// </summary>
bool FileExists(string path);
/// <summary>
/// Create a stream that can read and/or write a file on the given path.
/// </summary>
Stream CreateFileStream(string path, FileStreamModes mode);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9e114e4d1a092534796049799a691aa8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: