Better handling of empty files in remote storage

This commit is contained in:
James King 2019-07-19 22:02:58 +02:00
parent 26a64f64e7
commit 7445503580
2 changed files with 21 additions and 4 deletions

View File

@ -80,6 +80,8 @@ public override void Close()
if ( _closed ) return;
_closed = true;
_file.SizeInBytes = _written;
remoteStorage.native.FileWriteStreamClose( _handle );
_file.remoteStorage.OnWrittenNewFile( _file );

View File

@ -12,7 +12,7 @@ namespace Facepunch.Steamworks
/// </summary>
public class RemoteStorage : IDisposable
{
private static string NormalizePath( string path )
public static string NormalizePath( string path )
{
// TODO: DUMB HACK ALERT
@ -79,7 +79,7 @@ public RemoteFile CreateFile( string path )
InvalidateFiles();
var existing = Files.FirstOrDefault( x => x.FileName == path );
return existing ?? new RemoteFile( this, path, client.SteamId, 0 );
return existing ?? new RemoteFile( this, path, client.SteamId, -1 );
}
/// <summary>
@ -149,7 +149,17 @@ public byte[] ReadBytes( string path )
internal void OnWrittenNewFile( RemoteFile file )
{
if ( _files.Any( x => x.FileName == file.FileName ) ) return;
var match = _files.FirstOrDefault( x => x.FileName == file.FileName );
if ( match != null )
{
if ( match != file )
{
match.SizeInBytes = file.SizeInBytes;
}
return;
}
_files.Add( file );
file.Exists = true;
@ -179,6 +189,11 @@ private void UpdateFiles()
var name = NormalizePath( native.GetFileNameAndSize( i, out size ) );
var timestamp = native.GetFileTimestamp( name );
if ( size == 0 )
{
continue;
}
var existing = _files.FirstOrDefault( x => x.FileName == name );
if ( existing == null )
{