Files

38 lines
1.4 KiB
C#
Raw Permalink Normal View History

using Theriapolis.Game;
// Resolve content directories relative to the executable.
// Distribution: Data/ and Gfx/ sit next to the exe (absolute path)
// Development: walk up from the exe to find Content/Data and Content/Gfx
string dataDir = ResolveContentDir("Data");
string gfxDir = ResolveContentDir("Gfx");
static string ResolveContentDir(string subdir)
{
// 1. "<subdir>" next to the executable — distribution layout
string local = Path.Combine(AppContext.BaseDirectory, subdir);
if (Directory.Exists(local)) return local;
// 2. Walk up from the exe to find Content/<subdir> — development layout.
// Trim the trailing separator first: on Windows AppContext.BaseDirectory ends
// with '\', and GetDirectoryName on a trailing-slash path strips the slash
// without ascending, wasting one iteration.
string? dir = AppContext.BaseDirectory.TrimEnd(
Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
for (int i = 0; i < 6; i++)
{
if (dir is null) break;
string candidate = Path.Combine(dir, "Content", subdir);
if (Directory.Exists(candidate)) return candidate;
dir = Path.GetDirectoryName(dir);
}
return local; // missing-file errors will surface from the consumer with the bad path
}
using var game = new Game1
{
ContentDataDirectory = dataDir,
ContentGfxDirectory = gfxDir,
};
game.Run();