mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-01-13 07:08:05 +03:00
Added common utility functions to RemoteStorage
This commit is contained in:
parent
e3312d3387
commit
0a9f3f2281
@ -40,6 +40,28 @@ namespace Facepunch.Steamworks.Test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void ReadText()
|
||||||
|
{
|
||||||
|
using ( var client = new Steamworks.Client( 252490 ) )
|
||||||
|
{
|
||||||
|
var text = client.RemoteStorage.ReadString( "test.txt" );
|
||||||
|
|
||||||
|
Assert.IsNotNull( text );
|
||||||
|
Assert.AreEqual( text, "Hello world!" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void WriteText()
|
||||||
|
{
|
||||||
|
using ( var client = new Steamworks.Client( 252490 ) )
|
||||||
|
{
|
||||||
|
var result = client.RemoteStorage.WriteString( "test.txt", "Hello world!" );
|
||||||
|
Assert.IsTrue( result );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void WriteFiles()
|
public void WriteFiles()
|
||||||
{
|
{
|
||||||
|
@ -78,6 +78,62 @@ namespace Facepunch.Steamworks
|
|||||||
return existing ?? new RemoteFile( this, path, client.SteamId, 0 );
|
return existing ?? new RemoteFile( this, path, client.SteamId, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Opens the file if it exists, else returns null;
|
||||||
|
/// </summary>
|
||||||
|
public RemoteFile OpenFile( string path )
|
||||||
|
{
|
||||||
|
path = NormalizePath( path );
|
||||||
|
|
||||||
|
InvalidateFiles();
|
||||||
|
var existing = Files.FirstOrDefault( x => x.FileName == path );
|
||||||
|
return existing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Write all text to the file at the specified path. This
|
||||||
|
/// overwrites the contents - it does not append.
|
||||||
|
/// </summary>
|
||||||
|
public bool WriteString( string path, string text, Encoding encoding = null )
|
||||||
|
{
|
||||||
|
var file = CreateFile( path );
|
||||||
|
file.WriteAllText( text, encoding );
|
||||||
|
return file.Exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Write all data to the file at the specified path. This
|
||||||
|
/// overwrites the contents - it does not append.
|
||||||
|
/// </summary>
|
||||||
|
public bool WriteBytes( string path, byte[] data )
|
||||||
|
{
|
||||||
|
var file = CreateFile( path );
|
||||||
|
file.WriteAllBytes( data );
|
||||||
|
return file.Exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Read the entire contents of the file as a string.
|
||||||
|
/// Returns null if the file isn't found.
|
||||||
|
/// </summary>
|
||||||
|
public string ReadString( string path, Encoding encoding = null )
|
||||||
|
{
|
||||||
|
var file = OpenFile( path );
|
||||||
|
if ( file == null ) return null;
|
||||||
|
return file.ReadAllText( encoding );
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Read the entire contents of the file as raw data.
|
||||||
|
/// Returns null if the file isn't found.
|
||||||
|
/// </summary>
|
||||||
|
public byte[] ReadBytes( string path )
|
||||||
|
{
|
||||||
|
var file = OpenFile( path );
|
||||||
|
if ( file == null ) return null;
|
||||||
|
return file.ReadAllBytes();
|
||||||
|
}
|
||||||
|
|
||||||
internal void OnWrittenNewFile( RemoteFile file )
|
internal void OnWrittenNewFile( RemoteFile file )
|
||||||
{
|
{
|
||||||
if ( _files.Any( x => x.FileName == file.FileName ) ) return;
|
if ( _files.Any( x => x.FileName == file.FileName ) ) return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user