Skip to content

Commit

Permalink
Fixed issue that causes game to crash on load when tracker synchronis…
Browse files Browse the repository at this point in the history
…ation file was not previusly created
  • Loading branch information
Jarno458 committed Sep 2, 2021
1 parent d56fb9f commit 7aa108d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
2 changes: 1 addition & 1 deletion TsRandomizer.ItemTracker/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
[assembly: ComVisible(false)]
[assembly: Guid("77705356-2595-478C-B6BF-3BA82A887C8B")]
[assembly: AssemblyVersion("0.1.5.0")]
[assembly: AssemblyFileVersion("0.1.5.0")]
[assembly: AssemblyFileVersion("0.1.5.1")]
[assembly: InternalsVisibleTo("TsRandomizer.Tests")]
47 changes: 14 additions & 33 deletions TsRandomizer/ItemTracker/ItemTrackerUplink.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace TsRandomizer.ItemTracker
Expand All @@ -12,22 +11,21 @@ public static class ItemTrackerUplink

static readonly string StateFilePath = Path.GetTempPath() + "TsRandomizerItemTrackerState";

//static readonly FileStream FileStream = new FileStream(StateFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, FileSize);

//static readonly MemoryMappedFile MemoryMappedFile = GetMemoryMappedFile();
static ItemTrackerState lastSuccessfullRead;

public static void UpdateState(ItemTrackerState state)
{
var formatter = new BinaryFormatter();

using (var fileStream = new FileStream(StateFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, FileSize))
using (var memmoryMappedFIle = MemoryMappedFile.CreateFromFile(fileStream, "TsRandomizerItemTrackerState", fileStream.Length, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, true))
using (var stream = memmoryMappedFIle.CreateViewStream(0, fileStream.Length, MemoryMappedFileAccess.Write))
formatter.Serialize(stream, state);
{
fileStream.SetLength(FileSize);

using (var memmoryMappedFIle = MemoryMappedFile.CreateFromFile(fileStream, "TsRandomizerItemTrackerState", 0, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, true))
using (var stream = memmoryMappedFIle.CreateViewStream(0, 0, MemoryMappedFileAccess.Write))
formatter.Serialize(stream, state);
}

//using (var stream = GetMemoryMappedFileStream(MemoryMappedFileAccess.Write))
//formatter.Serialize(stream, state);
}

public static ItemTrackerState LoadState()
Expand All @@ -37,36 +35,19 @@ public static ItemTrackerState LoadState()
try
{
using (var fileStream = new FileStream(StateFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, FileSize))
using (var memmoryMappedFIle = MemoryMappedFile.CreateFromFile(fileStream, "TsRandomizerItemTrackerState", fileStream.Length, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, true))
using (var stream = memmoryMappedFIle.CreateViewStream(0, fileStream.Length, MemoryMappedFileAccess.Read))
lastSuccessfullRead = (ItemTrackerState)formatter.Deserialize(stream);
{
fileStream.SetLength(FileSize);

using (var memmoryMappedFIle = MemoryMappedFile.CreateFromFile(fileStream, "TsRandomizerItemTrackerState", 0, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, true))
using (var stream = memmoryMappedFIle.CreateViewStream(0, 0, MemoryMappedFileAccess.Read))
lastSuccessfullRead = (ItemTrackerState)formatter.Deserialize(stream);
}
}
catch
{
}

return lastSuccessfullRead;
}

/*static Stream GetMemoryMappedFileStream(MemoryMappedFileAccess access)
{
return MemoryMappedFile.CreateViewStream(0, FileStream.Length, access);
}
static MemoryMappedFile GetMemoryMappedFile()
{
try
{
//FileStream.SetLength(FileSize);
var m = MemoryMappedFile.CreateFromFile(FileStream,"TsRandomizerItemTrackerState",FileStream.Length, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, true);
return m;
}
catch (System.Exception e)
{
System.Console.WriteLine("ERROR opening MemoryMappedFile: " + e);
}
return null;
}*/
}
}
2 changes: 1 addition & 1 deletion TsRandomizer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[assembly: ComVisible(false)]
[assembly: Guid("694e46c5-fd46-4cc8-8b71-d381e154ccf7")]
[assembly: AssemblyVersion("0.0.9.14")]
[assembly: AssemblyFileVersion("0.0.9.14")]
[assembly: AssemblyFileVersion("0.0.9.15")]

[assembly: InternalsVisibleTo("TsRandomizer.Tests")]
[assembly: InternalsVisibleTo("TsRandomizerSeedGeneratah")]

0 comments on commit 7aa108d

Please sign in to comment.