The Harp of Yoba Redux

The Harp of Yoba Redux

6.4k Downloads

Custom Furniture fails loading asset due to absolute path

Pathoschild opened this issue ยท 0 comments

commented

Error

Custom Furniture fails with this error when loading an asset (see full log):

Custom Furniture failed loading content asset 'C:\[...]\Mods\CustomFurniture\Furniture\Coffee table\Coffee table b.png' from ModFolder. [...] Invalid filename. TitleContainer.OpenStream requires a relative URI.

Cause

The error happens because Custom Furniture uses Path.GetDirectoryName to get a folder name[1]:

data.folderName = Path.GetDirectoryName(file);

Despite the method name, it returns the absolute path (i.e. the "full name") of the containing folder, not the name. This directory path is then used in the asset path[2]:

 texture = CustomFurnitureMod.helper.Content.Load<Texture2D>(Path.Combine("Furniture", data.folderName, data.texture));

Due to the way Path.Combine works, this results in:

Path.Combine("Furniture", data.folderName, data.texture)
= Path.Combine("Furniture", "C:\Users\Rebecka\Desktop\Steam\steamapps\common\Stardew Valley\Mods\CustomFurniture\Furniture\Coffee table", "Coffee table b.png")
= "C:\Users\Rebecka\Desktop\Steam\steamapps\common\Stardew Valley\Mods\CustomFurniture\Furniture\Coffee table\Coffee table b.png"

Proposed fix

Change this code:

data.folderName = Path.GetDirectoryName(file);

to this:

data.folderName = new FileInfo(file).Directory.Name