mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 06:05:46 +03:00
Forcing BytesTotal/BytesUploaded to return sane information
This commit is contained in:
parent
6ce4e637d9
commit
d60ebf5fdd
@ -433,6 +433,21 @@ public void CreatePublish()
|
|||||||
item.Tags.Add( "Apple" );
|
item.Tags.Add( "Apple" );
|
||||||
item.Tags.Add( "Banana" );
|
item.Tags.Add( "Banana" );
|
||||||
|
|
||||||
|
// Make a folder
|
||||||
|
var testFolder = new System.IO.DirectoryInfo("BlahBlah");
|
||||||
|
if (!testFolder.Exists) testFolder.Create();
|
||||||
|
|
||||||
|
item.Folder = testFolder.FullName;
|
||||||
|
|
||||||
|
// Upload a file of random bytes
|
||||||
|
var rand = new Random();
|
||||||
|
var testFile = new byte[1024 * 1024 * 32];
|
||||||
|
rand.NextBytes(testFile);
|
||||||
|
System.IO.File.WriteAllBytes( testFolder.FullName + "/testfile1.bin", testFile);
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine(item.Folder);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
item.Publish();
|
item.Publish();
|
||||||
@ -440,7 +455,11 @@ public void CreatePublish()
|
|||||||
while ( item.Publishing )
|
while ( item.Publishing )
|
||||||
{
|
{
|
||||||
client.Update();
|
client.Update();
|
||||||
Thread.Sleep( 100 );
|
Thread.Sleep( 10 );
|
||||||
|
|
||||||
|
Console.WriteLine("Progress: " + item.Progress);
|
||||||
|
Console.WriteLine("BytesUploaded: " + item.BytesUploaded);
|
||||||
|
Console.WriteLine("BytesTotal: " + item.BytesTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.IsFalse( item.Publishing );
|
Assert.IsFalse( item.Publishing );
|
||||||
@ -469,6 +488,8 @@ public void CreatePublish()
|
|||||||
{
|
{
|
||||||
Console.WriteLine( "Deleting: {0}", item.Id );
|
Console.WriteLine( "Deleting: {0}", item.Id );
|
||||||
item.Delete();
|
item.Delete();
|
||||||
|
|
||||||
|
System.IO.File.Delete(testFolder.FullName + "/testfile.bin");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,56 +43,54 @@ public double Progress
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if ( !Publishing ) return 1.0;
|
var bt = BytesTotal;
|
||||||
if ( CreateItem != null ) return 0.0;
|
if (bt == 0) return 0;
|
||||||
if ( SubmitItemUpdate == null ) return 1.0;
|
|
||||||
|
|
||||||
ulong b = 0;
|
return (double)BytesUploaded / (double)bt;
|
||||||
ulong t = 0;
|
|
||||||
|
|
||||||
workshop.steamworks.native.ugc.GetItemUpdateProgress( UpdateHandle, out b, out t );
|
|
||||||
|
|
||||||
if ( t == 0 )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
return (double)b / (double) t;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int bytesUploaded = 0;
|
||||||
|
|
||||||
public int BytesUploaded
|
public int BytesUploaded
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if ( !Publishing ) return 0;
|
if ( !Publishing ) return bytesUploaded;
|
||||||
if ( CreateItem != null ) return 0;
|
if (UpdateHandle == 0) return bytesUploaded;
|
||||||
if ( SubmitItemUpdate == null ) return 0;
|
|
||||||
|
|
||||||
ulong b = 0;
|
ulong b = 0;
|
||||||
ulong t = 0;
|
ulong t = 0;
|
||||||
|
|
||||||
workshop.steamworks.native.ugc.GetItemUpdateProgress( UpdateHandle, out b, out t );
|
workshop.steamworks.native.ugc.GetItemUpdateProgress( UpdateHandle, out b, out t );
|
||||||
return (int) b;
|
bytesUploaded = Math.Max( bytesUploaded, (int) b );
|
||||||
|
return (int)bytesUploaded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int bytesTotal = 0;
|
||||||
|
|
||||||
public int BytesTotal
|
public int BytesTotal
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if ( !Publishing ) return 0;
|
if ( !Publishing ) return bytesTotal;
|
||||||
if ( CreateItem != null ) return 0;
|
if (UpdateHandle == 0 ) return bytesTotal;
|
||||||
if ( SubmitItemUpdate == null ) return 0;
|
|
||||||
|
|
||||||
ulong b = 0;
|
ulong b = 0;
|
||||||
ulong t = 0;
|
ulong t = 0;
|
||||||
|
|
||||||
workshop.steamworks.native.ugc.GetItemUpdateProgress( UpdateHandle, out b, out t );
|
workshop.steamworks.native.ugc.GetItemUpdateProgress( UpdateHandle, out b, out t );
|
||||||
return (int)t;
|
bytesTotal = Math.Max(bytesTotal, (int)t);
|
||||||
|
return (int)bytesTotal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Publish()
|
public void Publish()
|
||||||
{
|
{
|
||||||
|
bytesUploaded = 0;
|
||||||
|
bytesTotal = 0;
|
||||||
|
|
||||||
Publishing = true;
|
Publishing = true;
|
||||||
Error = null;
|
Error = null;
|
||||||
|
|
||||||
@ -117,6 +115,7 @@ private void OnItemCreated( SteamNative.CreateItemResult_t obj, bool Failed )
|
|||||||
{
|
{
|
||||||
NeedToAgreeToWorkshopLegal = obj.UserNeedsToAcceptWorkshopLegalAgreement;
|
NeedToAgreeToWorkshopLegal = obj.UserNeedsToAcceptWorkshopLegalAgreement;
|
||||||
CreateItem.Dispose();
|
CreateItem.Dispose();
|
||||||
|
CreateItem = null;
|
||||||
|
|
||||||
if ( obj.Result == SteamNative.Result.OK && !Failed )
|
if ( obj.Result == SteamNative.Result.OK && !Failed )
|
||||||
{
|
{
|
||||||
@ -188,6 +187,7 @@ private void OnChangesSubmitted( SteamNative.SubmitItemUpdateResult_t obj, bool
|
|||||||
if ( Failed )
|
if ( Failed )
|
||||||
throw new System.Exception( "CreateItemResult_t Failed" );
|
throw new System.Exception( "CreateItemResult_t Failed" );
|
||||||
|
|
||||||
|
UpdateHandle = 0;
|
||||||
SubmitItemUpdate = null;
|
SubmitItemUpdate = null;
|
||||||
NeedToAgreeToWorkshopLegal = obj.UserNeedsToAcceptWorkshopLegalAgreement;
|
NeedToAgreeToWorkshopLegal = obj.UserNeedsToAcceptWorkshopLegalAgreement;
|
||||||
Publishing = false;
|
Publishing = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user