add error handling inside the resource class

This commit is contained in:
murdle 2025-05-02 09:19:48 -07:00
parent 0d5dc9b3e5
commit 8c2c5f80bf
2 changed files with 2 additions and 6 deletions

View File

@ -10,11 +10,11 @@ public class Resource(string name)
return assembly.GetManifestResourceStream($"RobloxLegacy.Resources.{name}"); return assembly.GetManifestResourceStream($"RobloxLegacy.Resources.{name}");
} }
public byte[]? GetBytes() public byte[] GetBytes()
{ {
using var stream = GetStream(); using var stream = GetStream();
if (stream == null) if (stream == null)
return null; throw new Exception($"Failed to get {name} resource");
using var ms = new MemoryStream(); using var ms = new MemoryStream();
stream.CopyTo(ms); stream.CopyTo(ms);

View File

@ -58,8 +58,6 @@ public class VersionManager : IDisposable
private void WriteAppSettings() private void WriteAppSettings()
{ {
var appSettings = new Resource("AppSettings.xml").GetBytes(); var appSettings = new Resource("AppSettings.xml").GetBytes();
if (appSettings == null)
throw new Exception("Failed to get AppSettings resource");
File.WriteAllBytesAsync(Path.Combine(GetVersionPath(_currentVersion), "AppSettings.xml"), appSettings); File.WriteAllBytesAsync(Path.Combine(GetVersionPath(_currentVersion), "AppSettings.xml"), appSettings);
} }
@ -73,8 +71,6 @@ public class VersionManager : IDisposable
// now we can write the dll to the folder // now we can write the dll to the folder
var dllContents = new Resource(DllName).GetBytes(); var dllContents = new Resource(DllName).GetBytes();
if (dllContents == null)
throw new Exception("Failed to get dll resource");
File.WriteAllBytesAsync(Path.Combine(GetVersionPath(_currentVersion), DllName), dllContents); File.WriteAllBytesAsync(Path.Combine(GetVersionPath(_currentVersion), DllName), dllContents);
} }