Skip to content

Commit

Permalink
Add try-catch to check for read access to texture path.
Browse files Browse the repository at this point in the history
  • Loading branch information
BinaryConstruct committed Oct 27, 2020
1 parent 11bfcc2 commit 6d03d7d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/TEdit/Terraria/Textures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,23 @@ public Textures(IServiceProvider serviceProvider, GraphicsDevice gdDevice)

if (Directory.Exists(path))
{
ContentManager = new ContentManager(serviceProvider, path);
try
{
// try and load a single file, this checks for read access
using (StreamReader sr = new StreamReader(Path.Combine(path, "Images\\NPC_0.xnb")))
{
sr.BaseStream.ReadByte();
}

ContentManager = new ContentManager(serviceProvider, path);

}
catch (Exception ex)
{
ErrorLogging.LogException(ex);
System.Windows.Forms.MessageBox.Show($"Error loading textures from {path}.\r\nPlease check that this folder exists and TEdit has read access.\r\n\r\n{ex.Message}", "Error Loading Textures", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}

}
}

Expand Down

0 comments on commit 6d03d7d

Please sign in to comment.