This message was deleted.
# multiplatform
s
This message was deleted.
m
It is important to know how you access the files and where they are located. Otherwise it is impossible to answer this question.
d
If accessing as a resource it can be critical to prefix resource path with
/
k
tbh it doesn't work no matter where I store them. I tested it on the app level or in the user home (
'System.getProperty("user.home")
)
I will check if prefix change anything
d
By referencing DMG/MSI does this going that you're using Compose Multiplatform packaging?
k
yes
d
If so, recommend using Compose Multiplatform Resources
For which raw file resource handling is well documented and, I can attest, works
Read up on CMP Resources
k
I'm not sure if it will be possible - I need to store file for DataStore
d
Ok, let's take a step back. I don't feel you've really explained the use case clearly
1
What is the file, where does it get created, how does it get used
Then we can help
k
ok, I need a Path to a file which will be used to store data by androidx DataStore
so it looks like this
Copy code
PreferenceDataStoreFactory.createWithPath(
            corruptionHandler = ReplaceFileCorruptionHandler(
                produceNewData = { emptyPreferences() },
            ),
            produceFile = {
                val configPath = getAppConfigPath("CPU-Info")
                "$configPath/$USER_PREFERENCES_NAME.preferences_pb".toPath()
            },
        )

fun getAppConfigPath(appName: String): String {
    val os = System.getProperty("os.name").lowercase()
    val appNamePath = appName.toPath()
    val configPath = when {
        os.startsWith("windows") -> {
            val dir = getLocalAppDataPath() ?: "/".toPath()
            dir / appNamePath
        }

        os.contains("os x") -> {
            getHomePath() / "Library/Preferences".toPath() / appNamePath
        }

        else -> {
            val dir = getXdgConfigPath() ?: (getHomePath() / ".config".toPath())
            dir / appNamePath
        }
    }
    return configPath.toString()
}

private fun getHomePath() = System.getProperty("user.home").toPath()

private fun getXdgConfigPath() = System.getenv("XDG_CONFIG_HOME")?.toPath()

private fun getLocalAppDataPath() = System.getenv("LOCALAPPDATA")?.toPath()
maybe it is an issue in DataStore itself because it can create a folder for file but not file itself. Strange part is that it works perfectly fine without packaging
sorry for the confusion