mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-26 06:35:49 +03:00
Cleaning Workshop.Item
This commit is contained in:
parent
24affc78d8
commit
d06f662e6c
@ -394,13 +394,13 @@ public void DownloadFile()
|
|||||||
{
|
{
|
||||||
Assert.IsTrue( client.IsValid );
|
Assert.IsTrue( client.IsValid );
|
||||||
|
|
||||||
var item = client.Workshop.GetItem( 787387588 );
|
var item = client.Workshop.GetItem( 844466101 );
|
||||||
|
|
||||||
if ( !item.Installed )
|
if ( !item.Installed )
|
||||||
{
|
{
|
||||||
item.Download();
|
item.Download();
|
||||||
|
|
||||||
while ( item.Downloading )
|
while ( !item.Installed )
|
||||||
{
|
{
|
||||||
Thread.Sleep( 500 );
|
Thread.Sleep( 500 );
|
||||||
client.Update();
|
client.Update();
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using SteamNative;
|
||||||
|
|
||||||
namespace Facepunch.Steamworks
|
namespace Facepunch.Steamworks
|
||||||
{
|
{
|
||||||
@ -43,15 +44,12 @@ internal static Item From( SteamNative.SteamUGCDetails_t details, Workshop works
|
|||||||
item.VotesDown = details.VotesDown;
|
item.VotesDown = details.VotesDown;
|
||||||
item.Modified = new DateTime( details.TimeUpdated );
|
item.Modified = new DateTime( details.TimeUpdated );
|
||||||
item.Created = new DateTime( details.TimeCreated );
|
item.Created = new DateTime( details.TimeCreated );
|
||||||
item.UpdateState();
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Download( bool highPriority = true )
|
public void Download( bool highPriority = true )
|
||||||
{
|
{
|
||||||
UpdateState();
|
|
||||||
|
|
||||||
if ( Installed ) return;
|
if ( Installed ) return;
|
||||||
if ( Downloading ) return;
|
if ( Downloading ) return;
|
||||||
|
|
||||||
@ -63,8 +61,6 @@ public void Download( bool highPriority = true )
|
|||||||
|
|
||||||
workshop.OnFileDownloaded += OnFileDownloaded;
|
workshop.OnFileDownloaded += OnFileDownloaded;
|
||||||
workshop.OnItemInstalled += OnItemInstalled;
|
workshop.OnItemInstalled += OnItemInstalled;
|
||||||
UpdateState();
|
|
||||||
Downloading = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFileDownloaded( ulong fileid, Callbacks.Result result )
|
private void OnFileDownloaded( ulong fileid, Callbacks.Result result )
|
||||||
@ -72,10 +68,6 @@ private void OnFileDownloaded( ulong fileid, Callbacks.Result result )
|
|||||||
if ( fileid != Id ) return;
|
if ( fileid != Id ) return;
|
||||||
|
|
||||||
workshop.OnFileDownloaded -= OnFileDownloaded;
|
workshop.OnFileDownloaded -= OnFileDownloaded;
|
||||||
UpdateState();
|
|
||||||
|
|
||||||
if ( result == Callbacks.Result.OK )
|
|
||||||
Downloading = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnItemInstalled( ulong fileid )
|
private void OnItemInstalled( ulong fileid )
|
||||||
@ -83,10 +75,6 @@ private void OnItemInstalled( ulong fileid )
|
|||||||
if ( fileid != Id ) return;
|
if ( fileid != Id ) return;
|
||||||
|
|
||||||
workshop.OnItemInstalled -= OnItemInstalled;
|
workshop.OnItemInstalled -= OnItemInstalled;
|
||||||
UpdateState();
|
|
||||||
|
|
||||||
Downloading = false;
|
|
||||||
Installed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ulong BytesDownloaded { get { UpdateDownloadProgress(); return _BytesDownloaded; } }
|
public ulong BytesDownloaded { get { UpdateDownloadProgress(); return _BytesDownloaded; } }
|
||||||
@ -102,13 +90,46 @@ public double DownloadProgress
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Installed { get; private set; }
|
public bool Installed { get { return ( State & ItemState.Installed ) != 0; } }
|
||||||
public bool Downloading { get; private set; }
|
public bool Downloading { get { return ( State & ItemState.Downloading ) != 0; } }
|
||||||
public bool DownloadPending { get; private set; }
|
public bool DownloadPending { get { return ( State & ItemState.DownloadPending ) != 0; } }
|
||||||
public bool Subscribed { get; private set; }
|
public bool Subscribed { get { return ( State & ItemState.Subscribed ) != 0; } }
|
||||||
public bool NeedsUpdate { get; private set; }
|
public bool NeedsUpdate { get { return ( State & ItemState.NeedsUpdate ) != 0; } }
|
||||||
|
|
||||||
public DirectoryInfo Directory { get; private set; }
|
private SteamNative.ItemState State { get { return ( SteamNative.ItemState) workshop.ugc.GetItemState( Id ); } }
|
||||||
|
|
||||||
|
|
||||||
|
private DirectoryInfo _directory;
|
||||||
|
|
||||||
|
public DirectoryInfo Directory
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if ( _directory != null )
|
||||||
|
return _directory;
|
||||||
|
|
||||||
|
if ( !Installed )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
ulong sizeOnDisk;
|
||||||
|
string folder;
|
||||||
|
uint timestamp;
|
||||||
|
|
||||||
|
if ( workshop.ugc.GetItemInstallInfo( Id, out sizeOnDisk, out folder, out timestamp ) )
|
||||||
|
{
|
||||||
|
_directory = new DirectoryInfo( folder );
|
||||||
|
Size = sizeOnDisk;
|
||||||
|
|
||||||
|
if ( !_directory.Exists )
|
||||||
|
{
|
||||||
|
// Size = 0;
|
||||||
|
// _directory = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return _directory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ulong Size { get; private set; }
|
public ulong Size { get; private set; }
|
||||||
|
|
||||||
@ -119,40 +140,6 @@ internal void UpdateDownloadProgress()
|
|||||||
workshop.ugc.GetItemDownloadInfo( Id, out _BytesDownloaded, out _BytesTotal );
|
workshop.ugc.GetItemDownloadInfo( Id, out _BytesDownloaded, out _BytesTotal );
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void UpdateState()
|
|
||||||
{
|
|
||||||
var state = workshop.ugc.GetItemState( Id );
|
|
||||||
|
|
||||||
Installed = ( state & (uint)SteamNative.ItemState.Installed ) != 0;
|
|
||||||
Downloading = ( state & (uint)SteamNative.ItemState.Downloading ) != 0;
|
|
||||||
DownloadPending = ( state & (uint)SteamNative.ItemState.DownloadPending ) != 0;
|
|
||||||
Subscribed = ( state & (uint)SteamNative.ItemState.Subscribed ) != 0;
|
|
||||||
NeedsUpdate = ( state & (uint)SteamNative.ItemState.NeedsUpdate ) != 0;
|
|
||||||
|
|
||||||
if ( Installed && Directory == null )
|
|
||||||
{
|
|
||||||
Size = 0;
|
|
||||||
Directory = null;
|
|
||||||
|
|
||||||
ulong sizeOnDisk;
|
|
||||||
string folder;
|
|
||||||
uint timestamp;
|
|
||||||
if ( workshop.ugc.GetItemInstallInfo( Id, out sizeOnDisk, out folder, out timestamp ) )
|
|
||||||
{
|
|
||||||
Directory = new DirectoryInfo( folder );
|
|
||||||
Size = sizeOnDisk;
|
|
||||||
|
|
||||||
if ( !Directory.Exists )
|
|
||||||
{
|
|
||||||
Size = 0;
|
|
||||||
Directory = null;
|
|
||||||
Installed = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private int YourVote = 0;
|
private int YourVote = 0;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user