Skip to content

Commit

Permalink
fix self contained resource file
Browse files Browse the repository at this point in the history
  • Loading branch information
yatima1460 committed May 15, 2024
1 parent 602e7cb commit 29283cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>



<ItemGroup>
<None Remove="words_alpha.txt" />
<EmbeddedResource Include="words_alpha.txt" />
</ItemGroup>

<ItemGroup>
Expand Down
21 changes: 12 additions & 9 deletions Core/Heuristics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ internal static class Heuristics

static Heuristics()
{
string? path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (path == null)
var assembly = Assembly.GetExecutingAssembly();
var resourceName = assembly.GetManifestResourceNames().FirstOrDefault(name => name.EndsWith("words_alpha.txt"));

if (resourceName == null)
{
Console.WriteLine("Executing assembly path is null???");
Console.WriteLine("Can't find words dictionary in embedded resources");
dict = [];
return;
}
var DictPath = Path.Combine(path, "words_alpha.txt");
if (!File.Exists(DictPath))

using var stream = assembly.GetManifestResourceStream(resourceName);
if (stream != null)
{
Console.WriteLine("Can't find words dictionary");
dict = [];
return;
using var reader = new StreamReader(stream);
dict = reader.ReadToEnd().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToImmutableHashSet<string>();
}
dict = [.. File.ReadAllLines(DictPath)];

dict = [];
}


Expand Down

0 comments on commit 29283cf

Please sign in to comment.