Line 5: |
Line 5: |
| ==Metadata== | | ==Metadata== |
| ===Mod path=== | | ===Mod path=== |
− | SMAPI APIs use relative paths, so you rarely need the absolute path: | + | Before handling mod folder paths, be aware that: |
| + | * The '''mod's folder path is not consistent'''. The game is installed to different paths, Nexus mods are often unzipped into a folder like <tt>Mods/Your Mod Name 1.27.5-541-1-27-5-1598664794/YourModFolder</tt> by default, and players can organize their mod folders like <tt>Mods/For single-player/YourModFolder</tt>. |
| + | * Paths are formatted differently on Linux/Mac/Android vs Windows. |
| + | |
| + | You don't need to worry about that when using SMAPI APIs, which take relative paths and automatically fix the path format if needed: |
| <source lang="c#"> | | <source lang="c#"> |
| var data = helper.Data.ReadJsonFile<SomeDataModel>("assets/data.json"); | | var data = helper.Data.ReadJsonFile<SomeDataModel>("assets/data.json"); |
| </source> | | </source> |
| | | |
− | When you do need an absolute path, note that the '''mod's install path is not consistent'''. The game is installed to different paths, Nexus mods are often unzipped into a folder like <tt>Mods/Your Mod Name 1.27.5-541-1-27-5-1598664794/YourModFolder</tt> by default, and players can organize their mod folders like <tt>Mods/For single-player/YourModFolder</tt>. You should use the <code>this.Helper.DirectoryPath</code> to get an absolute path if you need it:
| + | If you really need a full path, you should use <tt>this.Helper.DirectoryPath</tt> and <tt>Path.Combine</tt> to get it: |
| <source lang="c#"> | | <source lang="c#"> |
− | string filePath = Path.Combine(this.Helper.DirectoryPath, "assets", "data.json"); | + | string path = Path.Combine(this.Helper.DirectoryPath, "assets", "data.json"); // "assets/data.json" in the current mod's folder |
− | var file = new FileInfo(filePath); | + | var file = new FileInfo(path); |
| </source> | | </source> |
| | | |
− | See ''[[#Constants|Constants]]'' for other paths. | + | See ''[[#Constants|Constants]]'' for other paths like the game folder. |
| | | |
| ===Constants=== | | ===Constants=== |