• Hi Guest!

    We are extremely excited to announce the release of our first Beta for VaM2, the next generation of Virt-A-Mate which is currently in development.
    To participate in the Beta, a subscription to the Entertainer or Creator Tier is required. Once subscribed, download instructions can be found here.

    Click here for information and guides regarding the VaM2 beta. Join our Discord server for more announcements and community discussion about VaM2.

Reading a .json file inside my own package

mrmr32

Well-known member
Joined
Sep 4, 2022
Messages
124
Reactions
333
Hi, I have to read a .json with information that I'll include before building the plugin.

I've read files before, but they were physical files; not files inside a package.
I've tried to do something similar to the .cslist syntax and I've come with this solution: `SuperController.singleton.GetFilesAtPath("mrmr32.UVSwapper." + PLUGIN_VERSION + ":/" + path)`, but it always return an empty array (but at least it doesn't throw any error).
Anyone has done it before, or knows a plugin that does it?

Thanks.
 
SPQR's code should do.

However, to automatically get the "SPQR.SPQRAlive.34:/" part, I recommend using this helpful method from MacGruber_Utils.cs
C#:
string text = FileManagerSecure.ReadAllText(Utils.GetPackagePath(this) + "Saves/scene/Alive/Alive Demo.json");
It autodetects the package you are in, so you don't have to worry about version numbers increasing. It also returns just an empty string, if you are just a local plugin not (yet) in a VAR package. So, it still works in that case, too.

If you don't wanna depend on any of my packages or don't want make your plugin CC-BY-SA to be able to include a copy of MacGruber_Utils.cs in your own VAR, you can also use this snippet under CC-BY conditions (so, without the "SA" part):
C#:
        // Get path prefix of the package that contains our plugin.
        private string GetPackagePath()
        {              
            string id = name.Substring(0, name.IndexOf('_'));
            string filename = manager.GetJSON()["plugins"][id].Value;
            int idx = filename.IndexOf(":/");
            if (idx >= 0)
                return filename.Substring(0, idx+2);
            else
                return string.Empty;
        }
 
Back
Top Bottom