Skip to content

Commit e97f989

Browse files
committed
better file resolving
1 parent 32344dd commit e97f989

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

src/main/kotlin/dev/dediamondpro/resourcify/config/Config.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
package dev.dediamondpro.resourcify.config
1919

2020
import dev.dediamondpro.resourcify.Constants
21+
import dev.dediamondpro.resourcify.platform.Platform
2122
import dev.dediamondpro.resourcify.services.modrinth.ModrinthService
2223
import dev.dediamondpro.resourcify.util.fromJson
2324
import dev.dediamondpro.resourcify.util.toJson
24-
import net.minecraft.client.Minecraft
25-
import java.io.File
2625

2726
class Config {
2827
var defaultService: String = ModrinthService.getName()
@@ -36,7 +35,7 @@ class Config {
3635
var worldsEnabled: Boolean = true
3736

3837
companion object {
39-
private val configFile = File("config/resourcify.json", Minecraft.getInstance().gameDirectory.path)
38+
private val configFile = Platform.getFileInGameDir("config/resourcify.json")
4039
val instance: Config
4140

4241
init {

src/main/kotlin/dev/dediamondpro/resourcify/gui/world/DownloadWorldTab.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package dev.dediamondpro.resourcify.gui.world
22

33
import dev.dediamondpro.resourcify.gui.browsepage.BrowseScreen
4+
import dev.dediamondpro.resourcify.platform.Platform
45
import dev.dediamondpro.resourcify.services.ProjectType
56
import gg.essential.universal.UScreen
67
import net.minecraft.client.gui.components.AbstractWidget
78
import net.minecraft.client.gui.components.tabs.Tab
89
import net.minecraft.client.gui.navigation.ScreenRectangle
910
import net.minecraft.network.chat.Component
10-
import java.io.File
1111
import java.util.function.Consumer
1212

1313
class DownloadWorldTab : Tab {
@@ -22,6 +22,6 @@ class DownloadWorldTab : Tab {
2222
}
2323

2424
fun onClick() {
25-
UScreen.displayScreen(BrowseScreen(ProjectType.WORLD, File("./saves")))
25+
UScreen.displayScreen(BrowseScreen(ProjectType.WORLD, Platform.getFileInGameDir("saves")))
2626
}
2727
}

src/main/kotlin/dev/dediamondpro/resourcify/platform/Platform.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package dev.dediamondpro.resourcify.platform
1919

2020
import net.minecraft.SharedConstants
21+
import net.minecraft.client.Minecraft
2122
import net.minecraft.client.gui.screens.Screen
2223
import net.minecraft.client.resources.language.I18n
2324
import net.minecraft.network.chat.contents.TranslatableContents
@@ -67,4 +68,8 @@ object Platform {
6768
return resources.content
6869
//?}
6970
}
71+
72+
fun getFileInGameDir(name: String): File {
73+
return File(Minecraft.getInstance().gameDirectory, name)
74+
}
7075
}

src/main/kotlin/dev/dediamondpro/resourcify/services/ProjectType.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package dev.dediamondpro.resourcify.services
1919

2020
import dev.dediamondpro.resourcify.config.Config
2121
import dev.dediamondpro.resourcify.mixins.PackScreenAccessor
22+
import dev.dediamondpro.resourcify.platform.Platform
2223
import net.minecraft.client.gui.screens.Screen
2324
import java.io.File
2425

@@ -64,9 +65,9 @@ enum class ProjectType(
6465
return when(this) {
6566
RESOURCE_PACK -> (screen as PackScreenAccessor).directory.toFile()
6667
DATA_PACK -> (screen as PackScreenAccessor).directory.toFile()
67-
IRIS_SHADER -> File("./shaderpacks")
68-
OPTIFINE_SHADER -> File("./shaderpacks")
69-
WORLD -> File("./saves")
68+
IRIS_SHADER -> Platform.getFileInGameDir("shaderpacks")
69+
OPTIFINE_SHADER -> Platform.getFileInGameDir("shaderpacks")
70+
WORLD -> Platform.getFileInGameDir("saves")
7071
else -> error("Unknown project type: $this")
7172
}
7273
}
@@ -80,10 +81,10 @@ enum class ProjectType(
8081
return when (this) {
8182
currentType -> currentFolder
8283
// Get folder on best-effort basis
83-
RESOURCE_PACK -> File("./resourcepacks")
84-
IRIS_SHADER -> File("./shaderpacks")
85-
OPTIFINE_SHADER -> File("./shaderpacks")
86-
WORLD -> File("./saves")
84+
RESOURCE_PACK -> Platform.getFileInGameDir("resourcepacks")
85+
IRIS_SHADER -> Platform.getFileInGameDir("shaderpacks")
86+
OPTIFINE_SHADER -> Platform.getFileInGameDir("shaderpacks")
87+
WORLD -> Platform.getFileInGameDir("saves")
8788
else -> null
8889
}
8990
}

src/main/kotlin/dev/dediamondpro/resourcify/util/DownloadManager.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package dev.dediamondpro.resourcify.util
1919

2020
import dev.dediamondpro.resourcify.Constants
21+
import dev.dediamondpro.resourcify.platform.Platform
2122
import java.io.File
2223
import java.net.URI
2324
import java.nio.file.Files
@@ -27,7 +28,7 @@ import java.util.zip.ZipEntry
2728
import java.util.zip.ZipFile
2829

2930
object DownloadManager {
30-
private val tempFolder = File("./resourcify-temp")
31+
private val tempFolder = Platform.getFileInGameDir("resourcify-temp")
3132

3233
@get:Synchronized
3334
private val queuedDownloads = mutableMapOf<URI, QueuedDownload>()

0 commit comments

Comments
 (0)