/// <summary> /// Opens the archive and loads it into memory (don't use to big files for now!) /// </summary> /// <returns>True when all went ok.</returns> public bool Prepare(string archiveFilename) { // Ignores the call if it's called for a second time! if (this.binArchive == null) { using (var fileStream = File.OpenRead(archiveFilename)) { this.binArchive = ProtoBuf.Serializer.Deserialize <BinArchive>(fileStream); this.archiveFilename = archiveFilename; } } return(this.binArchive != null); }
public static bool CreateArchive(string filename, string version) { // The GeneratedPorotocolBufferClasses.cs is generated from the .proto file (should include this in the build steps). // Copy the .proto to D:\git\protobuf-net\ProtoGen\bin\Debug // Run this command: D:\git\protobuf-net\ProtoGen\bin\Debug>protogen -i:bin_archive.proto -ns:BinArchiver -o:GeneratedProtocolBufferClasses.cs // Now copy output.cs to this local project. Will do for the moment. var binArchive = new BinArchive(); binArchive.version = version; binArchive.time = Helpers.convertToUnixTimeMilliseconds(DateTime.UtcNow); // We can crypt the firmware file, and we cannot crypt it. Supply them both and see if you can get back the same thing twice, would be great. using (var file = File.Create(filename)) { Serializer.Serialize(file, binArchive); } return(true); }