the rest of the client

This commit is contained in:
Chris Forbes
2010-01-16 18:36:04 +13:00
parent 9b011e3ada
commit e01f684878

View File

@@ -1,10 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.FileFormats;
using System.IO; using System.IO;
using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using OpenRa.FileFormats;
namespace OpenRa.Game namespace OpenRa.Game
{ {
@@ -24,15 +23,23 @@ namespace OpenRa.Game
BeginDownload(); BeginDownload();
} }
class Chunk { public int Index = 0; public int Count = 0; public string Data = ""; }
public static void ReceiveChunk(string data) public static void ReceiveChunk(string data)
{ {
var c = new Chunk();
FieldLoader.Load(c, new MiniYaml(null, MiniYaml.FromString(data)));
var bytes = Convert.FromBase64String(c.Data);
content.Write(bytes, 0, bytes.Length);
if (c.Index == c.Count - 1)
EndDownload();
} }
static void BeginDownload() static void BeginDownload()
{ {
if (missingPackages.Count == 0) if (missingPackages.Count == 0) // we're finished downloading resources!
{ // we're finished downloading resources! {
currentPackage = null; currentPackage = null;
return; return;
} }
@@ -41,11 +48,21 @@ namespace OpenRa.Game
missingPackages.RemoveAt(0); missingPackages.RemoveAt(0);
content = new MemoryStream(); content = new MemoryStream();
Game.controller.AddOrder(
new Order("RequestFile", null, null, int2.Zero, currentPackage)
{ IsImmediate = true });
} }
static void EndDownload() static void EndDownload()
{ {
File.WriteAllBytes(currentPackage.Split(':')[0], content.ToArray()); // commit this data to disk
var parts = currentPackage.Split(':');
File.WriteAllBytes(parts[0], content.ToArray());
if (CalculateSHA1(parts[0]) != parts[1])
throw new InvalidOperationException("Broken download");
currentPackage = null; currentPackage = null;
BeginDownload(); BeginDownload();