added AssetInfo; this is the start of syncing files over netplay
This commit is contained in:
33
OpenRa.DataStructures/AssetInfo.cs
Normal file
33
OpenRa.DataStructures/AssetInfo.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
namespace OpenRa
|
||||||
|
{
|
||||||
|
class AssetInfo
|
||||||
|
{
|
||||||
|
public readonly string Filename;
|
||||||
|
public readonly string Hash;
|
||||||
|
|
||||||
|
public AssetInfo(string filename, string hash)
|
||||||
|
{
|
||||||
|
Filename = filename;
|
||||||
|
Hash = hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
static string GetHash(string filename)
|
||||||
|
{
|
||||||
|
using (var csp = SHA1.Create())
|
||||||
|
return new string(csp.ComputeHash(File.ReadAllBytes(filename))
|
||||||
|
.SelectMany(a => a.ToString("x2")).ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AssetInfo FromLocalFile(string filename)
|
||||||
|
{
|
||||||
|
return new AssetInfo(filename, GetHash(filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* todo: perf: cache this */
|
||||||
|
public bool IsPresent() { return File.Exists(Filename) && (Hash == GetHash(Filename)); }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
<OldToolsVersion>2.0</OldToolsVersion>
|
<OldToolsVersion>2.0</OldToolsVersion>
|
||||||
<UpgradeBackupLocation>
|
<UpgradeBackupLocation>
|
||||||
</UpgradeBackupLocation>
|
</UpgradeBackupLocation>
|
||||||
|
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
@@ -33,11 +34,15 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core">
|
||||||
|
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="AssetInfo.cs" />
|
||||||
<Compile Include="float2.cs" />
|
<Compile Include="float2.cs" />
|
||||||
<Compile Include="int2.cs" />
|
<Compile Include="int2.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user