コード例 #1
0
ファイル: main.c プロジェクト: yaybu/Yaybu.app
int main(int argc, char * *argv, char * const *envp)
{
    int rval = 0;
    char exec_path[PATH_MAX+1];
    char resolved_path[PATH_MAX+1];
    uint32_t exec_path_size = sizeof(exec_path);
    CFStringRef argv0_string;
    CFURLRef argv0_url;
    char *argv0 = NULL;
    char *root = NULL;

    if (bind_CoreFoundation()) {
        fprintf(stderr, "CoreFoundation not found or functions missing\n");
        return -1;
    }

    if (_NSGetExecutablePath(exec_path, &exec_path_size) != 0) {
        fprintf(stderr, "_NSGetExecutablePath failed to find current executable\n");
        return -1;
    }
    exec_path[exec_path_size] = '\0';

    realpath(exec_path, resolved_path);
    root = dirname(dirname(dirname(resolved_path)));

    argv0_url = py2app_CFURLCreateFromFileSystemRepresentation(
        NULL,
        (uint8_t *)root,
        strlen(root),
        true
        );

    if (!argv0_url) {
        fprintf(stderr, "Could not cast '%s' to CFURL!\n", root);
        return -1;
    }

    py2app_main_bundle = py2app_CFBundleCreate(NULL, argv0_url);

    if (!py2app_main_bundle) {
        fprintf(stderr, "Not bundled, exiting\n");
        return -1;
    }

    py2app_pool = py2app_CFArrayCreateMutable(NULL, 0, py2app_kCFTypeArrayCallBacks);
    if (!py2app_pool) {
        fprintf(stderr, "Couldn't create global pool\n");
        return -1;
    }
    rval = py2app_main(argc, argv, envp);
    py2app_CFRelease(py2app_pool);
    py2app_CFRelease(py2app_main_bundle);
    py2app_CFRelease(argv0_url);
    // py2app_CFRelease(argv0_string);
    // free(argv0);
    return rval;
}
コード例 #2
0
ファイル: main.c プロジェクト: asuc-octo/tabulator
int
main(int argc, char * const *argv, char * const *envp)
{
    int rval;

#ifndef PY2APP_SECONDARY
    /* Running as a GUI app started by launch
     * services, try to redirect stdout/stderr
     * to ASL.
     *
     * NOTE: Detecting application bundles on OSX 10.9
     * is annoyingly hard, the devnull trick is the least
     * worst option I've found yet.
     */
    struct stat st;
    struct utsname uts;
    int is_app_bundle = 1;

    if (uname(&uts) != -1) {
        if (strcmp(uts.release, "13.") <= 0) {
	    /* OSX 10.8 or earlier */
            if (!have_psn_arg(argc, argv)) {
                is_app_bundle = 0;
	    }
	} else {
	    /* OSX 10.9 or later */
            if (fstat(1, &st) != -1) {
	        if (!S_ISCHR(st.st_mode) ||
	            major(st.st_dev) != 3 ||
     	            minor(st.st_dev) != 2) {

    	    	        /* We appear to be launched from the
			 * command-line after all.
		         */
		        is_app_bundle = st.st_dev;
	        }
            }
        }
    }


    if (is_app_bundle) {
        const char *bname;
        setenv("_PY2APP_LAUNCHED_", "1", 1);

        bname = strrchr(argv[0], '/');
        if (bname == NULL) {
	    bname = argv[0];
        } else {
	    bname++;
        }

        setup_asl(bname);
    }
#endif /* !PY2APP_SECONDARY */

    if (bind_CoreFoundation()) {
        fprintf(stderr, "CoreFoundation not found or functions missing\n");
        return -1;
    }
    if (!CFBundleGetMainBundle()) {
        fprintf(stderr, "Not bundled, exiting\n");
        return -1;
    }
    py2app_pool = py2app_CFArrayCreateMutable(NULL, 0, py2app_kCFTypeArrayCallBacks);
    if (!py2app_pool) {
        fprintf(stderr, "Couldn't create global pool\n");
        return -1;
    }
    rval = py2app_main(argc, argv, envp);
    py2app_CFRelease(py2app_pool);
    return rval;
}