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; if ( _closed ) return;
_closed = true; _closed = true;
_file.SizeInBytes = _written;
remoteStorage.native.FileWriteStreamClose( _handle ); remoteStorage.native.FileWriteStreamClose( _handle );
_file.remoteStorage.OnWrittenNewFile( _file ); _file.remoteStorage.OnWrittenNewFile( _file );

View File

@ -12,7 +12,7 @@ namespace Facepunch.Steamworks
/// </summary> /// </summary>
public class RemoteStorage : IDisposable public class RemoteStorage : IDisposable
{ {
private static string NormalizePath( string path ) public static string NormalizePath( string path )
{ {
// TODO: DUMB HACK ALERT // TODO: DUMB HACK ALERT
@ -79,7 +79,7 @@ public RemoteFile CreateFile( string path )
InvalidateFiles(); InvalidateFiles();
var existing = Files.FirstOrDefault( x => x.FileName == path ); 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> /// <summary>
@ -149,7 +149,17 @@ public byte[] ReadBytes( string path )
internal void OnWrittenNewFile( RemoteFile file ) 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 ); _files.Add( file );
file.Exists = true; file.Exists = true;
@ -177,7 +187,12 @@ private void UpdateFiles()
{ {
int size; int size;
var name = NormalizePath( native.GetFileNameAndSize( i, out size ) ); var name = NormalizePath( native.GetFileNameAndSize( i, out size ) );
var timestamp = native.GetFileTimestamp(name); var timestamp = native.GetFileTimestamp( name );
if ( size == 0 )
{
continue;
}
var existing = _files.FirstOrDefault( x => x.FileName == name ); var existing = _files.FirstOrDefault( x => x.FileName == name );
if ( existing == null ) if ( existing == null )