Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix access of files relative to the program directory #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Fushigi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
if (!Path.Exists("imgui.ini"))
{
Console.WriteLine("Creating imgui.ini...");
File.WriteAllText("imgui.ini", File.ReadAllText(Path.Combine("res", "imgui-default.ini")));
File.WriteAllText("imgui.ini", File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "res", "imgui-default.ini")));
Console.WriteLine("Created!");
};

Expand Down
8 changes: 4 additions & 4 deletions Fushigi/gl/Bfres/Agl/AglLightmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public static void Init(GL gl)
Framebuffer = new GLFramebuffer(gl, FramebufferTarget.Framebuffer);
Framebuffer.SetDrawBuffers(buffers);

NormalsTexture = new DDSTextureRender(gl, Path.Combine("res", "bfres", "normals.dds"));
LUTTexture = new DDSTextureRender(gl, Path.Combine("res", "bfres", "gradient.dds"));
NormalsTexture = new DDSTextureRender(gl, Path.Combine(AppContext.BaseDirectory, "res", "bfres", "normals.dds"));
LUTTexture = new DDSTextureRender(gl, Path.Combine(AppContext.BaseDirectory, "res", "bfres", "gradient.dds"));

ScreenQuadRender = new ScreenQuad(gl, 1f);
}
Expand All @@ -67,8 +67,8 @@ public void RenderLevel(GL gl, GLTexture output, int mip_level)
var size = output.Width / (uint)Math.Pow(2, mip_level);

var shader = GLShaderCache.GetShader(gl, "Lightmap",
Path.Combine("res", "shaders", "Lightmap.vert"),
Path.Combine("res", "shaders", "Lightmap.frag"));
Path.Combine(AppContext.BaseDirectory, "res", "shaders", "Lightmap.vert"),
Path.Combine(AppContext.BaseDirectory, "res", "shaders", "Lightmap.frag"));

shader.Use();
Framebuffer.Bind();
Expand Down
4 changes: 2 additions & 2 deletions Fushigi/gl/Bfres/BfresMaterialRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public void Init(GL gl, BfresRender.BfresModel modelRender, BfresRender.BfresMes
Name = material.Name;

Shader = GLShaderCache.GetShader(gl, "Bfres",
Path.Combine("res", "shaders", "Bfres.vert"),
Path.Combine("res", "shaders", "Bfres.frag"));
Path.Combine(AppContext.BaseDirectory, "res", "shaders", "Bfres.vert"),
Path.Combine(AppContext.BaseDirectory, "res", "shaders", "Bfres.frag"));

GsysRenderState.Init(material);
GsysShaderRender.Init(gl, modelRender, meshRender, shape, material);
Expand Down
4 changes: 2 additions & 2 deletions Fushigi/gl/Bfres/Gsys/GsysResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public void Init(GL gl)
DiffuseLightmap = GLTextureCube.CreateEmpty(gl, 4);
SpecularLightmap = GLTextureCube.CreateEmpty(gl, 4);

CubeMap = new DDSTextureRender(gl, Path.Combine("res", "bfres", "CubemapHDR.dds"), TextureTarget.TextureCubeMapArray);
// DiffuseLightmap = new DDSTextureRender(gl, Path.Combine("res", "bfres", "CubemapLightmap.dds"), TextureTarget.TextureCubeMap);
CubeMap = new DDSTextureRender(gl, Path.Combine(AppContext.BaseDirectory, "res", "bfres", "CubemapHDR.dds"), TextureTarget.TextureCubeMapArray);
// DiffuseLightmap = new DDSTextureRender(gl, Path.Combine(AppContext.BaseDirectory, "res", "bfres", "CubemapLightmap.dds"), TextureTarget.TextureCubeMap);

DiffuseLightmap.Bind();
DiffuseLightmap.WrapS = TextureWrapMode.ClampToEdge;
Expand Down
4 changes: 2 additions & 2 deletions Fushigi/gl/HDRScreenBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void Render(GL gl, int width, int height, GLTexture2D input)
gl.Viewport(0, 0, Framebuffer.Width, Framebuffer.Height);

var shader = GLShaderCache.GetShader(gl, "PostEffect",
Path.Combine("res", "shaders", "screen.vert"),
Path.Combine("res", "shaders", "screen.frag"));
Path.Combine(AppContext.BaseDirectory, "res", "shaders", "screen.vert"),
Path.Combine(AppContext.BaseDirectory, "res", "shaders", "screen.frag"));

shader.Use();
shader.SetTexture("screenTexture", input, 1);
Expand Down
4 changes: 2 additions & 2 deletions Fushigi/gl/Materials/BasicMaterial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class BasicMaterial
public void Render(GL gl, Matrix4x4 matrix)
{
Shader = GLShaderCache.GetShader(gl, "Basic",
Path.Combine("res", "shaders", "Basic.vert"),
Path.Combine("res", "shaders", "Basic.frag"));
Path.Combine(AppContext.BaseDirectory, "res", "shaders", "Basic.vert"),
Path.Combine(AppContext.BaseDirectory, "res", "shaders", "Basic.frag"));

Shader.Use();
Shader.SetUniform("mtxCam", matrix);
Expand Down
4 changes: 2 additions & 2 deletions Fushigi/gl/Primitives/Plane2DRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public void RenderTest(Camera camera)
Image = GLTexture2D.Load(_gl, "Wood.png");

var shader = GLShaderCache.GetShader(_gl, "Basic",
Path.Combine("res", "shaders", "Basic.vert"),
Path.Combine("res", "shaders", "Basic.frag"));
Path.Combine(AppContext.BaseDirectory, "res", "shaders", "Basic.vert"),
Path.Combine(AppContext.BaseDirectory, "res", "shaders", "Basic.frag"));

shader.Use();
shader.SetUniform("hasTexture", Image != null ? 1 : 0);
Expand Down
2 changes: 1 addition & 1 deletion Fushigi/gl/Textures/GLImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static GLTexture GetDefaultTexture(GL gl)
{
//Default texture
if (DefaultTexture == null)
DefaultTexture = GLTexture2D.Load(gl, Path.Combine("res", "DefaultTexture.png"));
DefaultTexture = GLTexture2D.Load(gl, Path.Combine(AppContext.BaseDirectory, "res", "DefaultTexture.png"));

return DefaultTexture;
}
Expand Down
2 changes: 1 addition & 1 deletion Fushigi/param/ParamLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void Load()
mParams = new Dictionary<string, ParamHolder>();
var nodes = JsonNode.Parse(
File.ReadAllText(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "res", "AreaParam.json")
Path.Combine(AppContext.BaseDirectory, "res", "AreaParam.json")
)
).AsObject();
ParamHolder areaParms = new ParamHolder();
Expand Down
10 changes: 5 additions & 5 deletions Fushigi/ui/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,27 @@ public MainWindow()

{
mDefaultFont = io.Fonts.AddFontFromFileTTF(
Path.Combine("res", "Font.ttf"),
Path.Combine(AppContext.BaseDirectory, "res", "Font.ttf"),
size, nativeConfig, io.Fonts.GetGlyphRangesDefault());

io.Fonts.AddFontFromFileTTF(
Path.Combine("res", "NotoSansCJKjp-Medium.otf"),
Path.Combine(AppContext.BaseDirectory, "res", "NotoSansCJKjp-Medium.otf"),
size, nativeConfigJP, io.Fonts.GetGlyphRangesJapanese());

//other fonts go here and follow the same schema
GCHandle rangeHandle = GCHandle.Alloc(new ushort[] { IconUtil.MIN_GLYPH_RANGE, IconUtil.MAX_GLYPH_RANGE, 0 }, GCHandleType.Pinned);
try
{
io.Fonts.AddFontFromFileTTF(
Path.Combine("res", "la-regular-400.ttf"),
Path.Combine(AppContext.BaseDirectory, "res", "la-regular-400.ttf"),
size, iconConfig, rangeHandle.AddrOfPinnedObject());

io.Fonts.AddFontFromFileTTF(
Path.Combine("res", "la-solid-900.ttf"),
Path.Combine(AppContext.BaseDirectory, "res", "la-solid-900.ttf"),
size, iconConfig, rangeHandle.AddrOfPinnedObject());

io.Fonts.AddFontFromFileTTF(
Path.Combine("res", "la-brands-400.ttf"),
Path.Combine(AppContext.BaseDirectory, "res", "la-brands-400.ttf"),
size, iconConfig, rangeHandle.AddrOfPinnedObject());

io.Fonts.Build();
Expand Down
6 changes: 3 additions & 3 deletions Fushigi/util/ActorIconLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ActorIconLoader

public static void Init()
{
string folder = Path.Combine("res", "actor_icons");
string actor_icons_zip = Path.Combine("res", "ActorIcons.zip");
string folder = Path.Combine(AppContext.BaseDirectory, "res", "actor_icons");
string actor_icons_zip = Path.Combine(AppContext.BaseDirectory, "res", "ActorIcons.zip");
if (!File.Exists(actor_icons_zip))
return;

Expand All @@ -38,7 +38,7 @@ public static void Init()

public static int GetIcon(GL gl, string gyml, string model)
{
string folder = Path.Combine("res", "actor_icons");
string folder = Path.Combine(AppContext.BaseDirectory, "res", "actor_icons");
string icon_path = Path.Combine(folder, $"{gyml}.bfres_{model}.png");

if (Icons.ContainsKey(icon_path))
Expand Down