JerboaBurrow / JellyCram

A Tetris inspired jelly-physics game with button mashing elements and minor frustration
https://jerboa-app.itch.io/jelly-cram
GNU General Public License v3.0
0 stars 0 forks source link

macOS files #81

Closed Jerboa-app closed 5 months ago

Jerboa-app commented 5 months ago
Jerboa-app commented 5 months ago

it's a mess

https://stackoverflow.com/questions/22694662/mac-os-x-can-i-write-application-files-within-the-app-bundle

https://stackoverflow.com/questions/5123361/finding-library-application-support-from-c

Jerboa-app commented 5 months ago

This code functions in a .app bundle which comes from apple... https://developer.apple.com/library/archive/qa/qa1549/_index.html

#include <glob.h>
#include <string>
#include <iostream>
#include <fstream>
#include <filesystem>

char* CreatePathByExpandingTildePath(char* path)
{
    glob_t globbuf;
    char **v;
    char *expandedPath = NULL, *result = NULL;

    if (path == NULL) { return "NULL"; }

    if (glob(path, GLOB_TILDE, NULL, &globbuf) == 0) //success
    {
        v = globbuf.gl_pathv; //list of matched pathnames
        expandedPath = v[0]; //number of matched pathnames, gl_pathc == 1

        result = (char*)calloc(1, strlen(expandedPath) + 1); //the extra char is for the null-termination
        if(result)
            strncpy(result, expandedPath, strlen(expandedPath) + 1); //copy the null-termination as well

        globfree(&globbuf);
    }

    return result;
}

int main()
{
    std::string home = CreatePathByExpandingTildePath("~/");
    std::cout << home << std::endl;
        std::string support = home+"Library/Application Support/t";

    if (!std::filesystem::exists(support)) { std::filesystem::create_directory(support); }
    std::ofstream out(support+"/data.json");
    out << "{ \"some\": 1 }";
    out.close();
}