static private void GetProblemsFromSeed() { string seedPath = SeedFilePath(); byte [] seedContents = System.IO.File.ReadAllBytes(seedPath); MemoryStream seedStream = new MemoryStream(seedContents); if (seedContents.Length == 0) { ThinksyPlugin.ShowEmergencyWindow("The seed file is empty! (" + seedPath + ")"); throw new Exception("The seed file is empty!"); } //Message.Problem.ProblemGetResponse problemGet = Message.Problem.ProblemGetResponse.ParseFrom (seedContents); //Message.Problem.ProblemGetResponse problemGet = ProtoBuf.Serializer.Deserialize<Message.Problem.ProblemGetResponse> (seedStream); ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer(); Message.Problem.ProblemGetResponse problemGet = customSerializer.Deserialize(seedStream, null, typeof(Message.Problem.ProblemGetResponse)) as Message.Problem.ProblemGetResponse; for (int i = 0; i < problemGet.problems.Count; i++) { Message.Problem.ProblemData problem = problemGet.problems[i]; ProblemKeeper.AddProblemsToProblemQueue(problem); } }
static private void ReplaceSeed(Message.Problem.ProblemGetResponse reply) { Logger.BasicLog("Replacing seed file."); MemoryStream stream = new MemoryStream(); ThinksyProtosSerializer customSerializer = new ThinksyProtosSerializer(); customSerializer.Serialize(stream, reply); byte[] replacementBytes = stream.ToArray(); try { FileStream newFile = System.IO.File.Create(PlayerSeedPath()); SenseixSession.DoFileFlagging(PlayerSeedPath()); newFile.Close(); } catch { ThinksyPlugin.ShowEmergencyWindow("An error occurred while creating a seedfile in " + PlayerSeedPath()); } stream.Close(); System.IO.File.WriteAllBytes(SeedFilePath(), replacementBytes); SenseixSession.DoFileFlagging(SeedFilePath()); }
static public void ReplaceQueue(Message.Problem.ProblemGetResponse reply) { ProblemKeeper.ReplaceSeed(reply); ProblemKeeper.DrainProblems(); ProblemKeeper.GetProblemsFromSeed(); }