GithubHelp home page GithubHelp logo

macOS files about jellycram HOT 2 CLOSED

Jerboa-app avatar Jerboa-app commented on June 19, 2024
macOS files

from jellycram.

Comments (2)

Jerboa-app avatar Jerboa-app commented on June 19, 2024

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

from jellycram.

Jerboa-app avatar Jerboa-app commented on June 19, 2024

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();
}

from jellycram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.