Commit 465e6d94 authored by mercury233's avatar mercury233

Fix multi replay

parent 3f8943fa
...@@ -200,10 +200,12 @@ public static class TcpHelper ...@@ -200,10 +200,12 @@ public static class TcpHelper
Program.I().shiftToServant(Program.I().selectServer); Program.I().shiftToServant(Program.I().selectServer);
} }
Program.I().cardDescription.RMSshow_none(InterString.Get("连接被断开。")); Program.I().cardDescription.RMSshow_none(InterString.Get("连接被断开。"));
packagesInRecord.Clear();
} }
else else
{ {
Program.I().cardDescription.RMSshow_none(InterString.Get("对方离开游戏,您现在可以截图。")); Program.I().cardDescription.RMSshow_none(InterString.Get("对方离开游戏,您现在可以截图。"));
packagesInRecord.Clear();
Program.I().ocgcore.forceMSquit(); Program.I().ocgcore.forceMSquit();
} }
...@@ -402,7 +404,7 @@ public static class TcpHelper ...@@ -402,7 +404,7 @@ public static class TcpHelper
Send(message); Send(message);
} }
static List<Package> packagesInRecord = new List<Package>(); public static List<Package> packagesInRecord = new List<Package>();
public static List<Package> readPackagesInRecord(string path) public static List<Package> readPackagesInRecord(string path)
{ {
...@@ -482,6 +484,10 @@ public static class TcpHelper ...@@ -482,6 +484,10 @@ public static class TcpHelper
startI = packagesInRecord.Count; startI = packagesInRecord.Count;
} }
packagesInRecord.Insert(startI, Program.I().ocgcore.getNamePacket()); packagesInRecord.Insert(startI, Program.I().ocgcore.getNamePacket());
if (File.Exists("replay/" + lastRecordName + ".yrp3d"))
{
File.Delete("replay/" + lastRecordName + ".yrp3d");
}
lastRecordName = UIHelper.getTimeString(); lastRecordName = UIHelper.getTimeString();
FileStream stream = File.Create("replay/" + lastRecordName + ".yrp3d"); FileStream stream = File.Create("replay/" + lastRecordName + ".yrp3d");
BinaryWriter writer = new BinaryWriter(stream); BinaryWriter writer = new BinaryWriter(stream);
...@@ -496,7 +502,7 @@ public static class TcpHelper ...@@ -496,7 +502,7 @@ public static class TcpHelper
stream.Close(); stream.Close();
} }
} }
packagesInRecord.Clear(); //packagesInRecord.Clear();
} }
catch (System.Exception e) catch (System.Exception e)
{ {
......
...@@ -2703,6 +2703,7 @@ public class Ocgcore : ServantWithCardDescription ...@@ -2703,6 +2703,7 @@ public class Ocgcore : ServantWithCardDescription
} }
File.Move("replay/" + TcpHelper.lastRecordName + ".yrp3d", "replay/" + winCaculator.input.value + ".yrp3d"); File.Move("replay/" + TcpHelper.lastRecordName + ".yrp3d", "replay/" + winCaculator.input.value + ".yrp3d");
} }
TcpHelper.lastRecordName = "";
} }
catch (Exception e) catch (Exception e)
{ {
......
...@@ -128,13 +128,13 @@ public class selectReplay : WindowServantSP ...@@ -128,13 +128,13 @@ public class selectReplay : WindowServantSP
new messageSystemValue { hint = "no", value = "no" }); new messageSystemValue { hint = "no", value = "no" });
} }
byte[] getYRPbuffer(string path) List<byte[]> getYRPbuffer(string path)
{ {
if (path.Substring(path.Length - 4, 4) == ".yrp") if (path.Substring(path.Length - 4, 4) == ".yrp")
{ {
return File.ReadAllBytes(path); return new List<byte[]> { File.ReadAllBytes(path) };
} }
byte[] returnValue = null; var returnValue = new List<byte[]>();
try try
{ {
var collection = TcpHelper.readPackagesInRecord(path); var collection = TcpHelper.readPackagesInRecord(path);
...@@ -142,23 +142,16 @@ public class selectReplay : WindowServantSP ...@@ -142,23 +142,16 @@ public class selectReplay : WindowServantSP
{ {
if (item.Fuction == (int)YGOSharp.OCGWrapper.Enums.GameMessage.sibyl_replay) if (item.Fuction == (int)YGOSharp.OCGWrapper.Enums.GameMessage.sibyl_replay)
{ {
returnValue = item.Data.reader.ReadToEnd(); byte[] replay = item.Data.reader.ReadToEnd();
break; // TODO: don't include other replays
returnValue.Add(replay);
} }
} }
} }
catch (Exception e) catch (Exception e)
{ {
Debug.Log(e); Debug.Log(e);
} }
if (returnValue != null)
{
if (returnValue.Length < 50)
{
returnValue = null;
}
}
return returnValue; return returnValue;
} }
...@@ -266,7 +259,7 @@ public class selectReplay : WindowServantSP ...@@ -266,7 +259,7 @@ public class selectReplay : WindowServantSP
} }
else else
{ {
yrp = getYRP(getYRPbuffer("replay/" + superScrollView.selectedString + ".yrp3d")); yrp = getYRP(getYRPbuffer("replay/" + superScrollView.selectedString + ".yrp3d")[0]);
} }
for (int i = 0; i < yrp.playerData.Count; i++) for (int i = 0; i < yrp.playerData.Count; i++)
{ {
...@@ -287,11 +280,13 @@ public class selectReplay : WindowServantSP ...@@ -287,11 +280,13 @@ public class selectReplay : WindowServantSP
if (yrp.playerData.Count == 0) if (yrp.playerData.Count == 0)
{ {
RMSshow_none(InterString.Get("录像没有录制完整。")); RMSshow_none(InterString.Get("录像没有录制完整。"));
RMSshow_none(InterString.Get("MATCH局中可能只有最后一局决斗才包含卡组信息。"));
} }
} }
catch (Exception) catch (Exception)
{ {
RMSshow_none(InterString.Get("录像没有录制完整。")); RMSshow_none(InterString.Get("录像没有录制完整。"));
RMSshow_none(InterString.Get("MATCH局中可能只有最后一局决斗才包含卡组信息。"));
} }
} }
...@@ -305,18 +300,24 @@ public class selectReplay : WindowServantSP ...@@ -305,18 +300,24 @@ public class selectReplay : WindowServantSP
{ {
if (File.Exists("replay/" + superScrollView.selectedString + ".yrp3d")) if (File.Exists("replay/" + superScrollView.selectedString + ".yrp3d"))
{ {
File.WriteAllBytes("replay/" + superScrollView.selectedString + ".yrp", getYRPbuffer("replay/" + superScrollView.selectedString + ".yrp3d")); var replays = getYRPbuffer("replay/" + superScrollView.selectedString + ".yrp3d");
RMSshow_none(InterString.Get("录像入库:[?]", "replay/" + superScrollView.selectedString + ".yrp")); for(int i = 1; i <= replays.Count; i++) {
string filename = "replay/" + superScrollView.selectedString + "-Game" + i + ".yrp";
File.WriteAllBytes(filename, replays[i - 1]);
RMSshow_none(InterString.Get("录像入库:[?]", filename));
}
printFile(); printFile();
} }
else else
{ {
RMSshow_none(InterString.Get("录像没有录制完整。")); RMSshow_none(InterString.Get("录像没有录制完整。"));
RMSshow_none(InterString.Get("MATCH局中可能只有最后一局决斗才包含旧版录像信息。"));
} }
} }
catch (Exception) catch (Exception)
{ {
RMSshow_none(InterString.Get("录像没有录制完整。")); RMSshow_none(InterString.Get("录像没有录制完整。"));
RMSshow_none(InterString.Get("MATCH局中可能只有最后一局决斗才包含旧版录像信息。"));
} }
} }
...@@ -375,7 +376,7 @@ public class selectReplay : WindowServantSP ...@@ -375,7 +376,7 @@ public class selectReplay : WindowServantSP
FileInfo[] fileInfos = (new DirectoryInfo("replay")).GetFiles(); FileInfo[] fileInfos = (new DirectoryInfo("replay")).GetFiles();
for (int i = 0; i < fileInfos.Length; i++) for (int i = 0; i < fileInfos.Length; i++)
{ {
if (fileInfos[i].Name.Length == 21) if (fileInfos[i].Name.Length == 21 || fileInfos[i].Name.Length == 25)
{ {
if (fileInfos[i].Name[2] == '-') if (fileInfos[i].Name[2] == '-')
{ {
...@@ -429,7 +430,8 @@ public class selectReplay : WindowServantSP ...@@ -429,7 +430,8 @@ public class selectReplay : WindowServantSP
if (precy != null) if (precy != null)
precy.dispose(); precy.dispose();
precy = new PrecyOcg(); precy = new PrecyOcg();
var collections = TcpHelper.getPackages(precy.ygopro.getYRP3dBuffer(getYRP(getYRPbuffer("replay/" + name + ".yrp3d")))); var replays = getYRPbuffer("replay/" + name + ".yrp3d");
var collections = TcpHelper.getPackages(precy.ygopro.getYRP3dBuffer(getYRP(replays[replays.Count - 1])));
pushCollection(collections); pushCollection(collections);
} }
else else
...@@ -457,6 +459,7 @@ public class selectReplay : WindowServantSP ...@@ -457,6 +459,7 @@ public class selectReplay : WindowServantSP
catch (Exception) catch (Exception)
{ {
RMSshow_none(InterString.Get("录像没有录制完整。")); RMSshow_none(InterString.Get("录像没有录制完整。"));
RMSshow_none(InterString.Get("MATCH局中可能只有最后一局决斗才包含旧版录像信息。"));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment