void gr_opengl_print_screen(const char *filename) { char tmp[MAX_PATH_LEN]; GLubyte *pixels = NULL; GLuint pbo = 0; // save to a "screenshots" directory and tack on the filename snprintf(tmp, MAX_PATH_LEN-1, "screenshots/%s.png", filename); _mkdir(os_get_config_path("screenshots").c_str()); // glReadBuffer(GL_FRONT); // now for the data if (Use_PBOs) { Assert( !pbo ); glGenBuffers(1, &pbo); if ( !pbo ) { return; } glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo); glBufferData(GL_PIXEL_PACK_BUFFER, (gr_screen.max_w * gr_screen.max_h * 4), NULL, GL_STATIC_READ); glReadBuffer(GL_FRONT); glReadPixels(0, 0, gr_screen.max_w, gr_screen.max_h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL); // map the image data so that we can save it to file pixels = (GLubyte*) glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY); } else { pixels = (GLubyte*) vm_malloc(gr_screen.max_w * gr_screen.max_h * 4, memory::quiet_alloc); if (pixels == NULL) { return; } glReadPixels(0, 0, gr_screen.max_w, gr_screen.max_h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, pixels); glFlush(); } if (!png_write_bitmap(os_get_config_path(tmp).c_str(), gr_screen.max_w, gr_screen.max_h, true, pixels)) { ReleaseWarning(LOCATION, "Failed to write screenshot to \"%s\".", os_get_config_path(tmp).c_str()); } if (pbo) { glUnmapBuffer(GL_PIXEL_PACK_BUFFER); pixels = NULL; glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); glDeleteBuffers(1, &pbo); } if (pixels != NULL) { vm_free(pixels); } }
static void profile_save(Profile *profile, const char *file) { FILE *fp = NULL; char tmp[MAX_PATH] = ""; char tmp2[MAX_PATH] = ""; if (profile == NULL) return; fp = fopen(os_get_config_path(file).c_str(), "wt"); if (fp == NULL) return; Section *sp = profile->sections; while (sp != NULL) { sprintf(tmp, NOX("[%s]\n"), sp->name); fputs(tmp, fp); KeyValue *kvp = sp->pairs; while (kvp != NULL) { sprintf(tmp2, NOX("%s=%s\n"), kvp->key, kvp->value); fputs(tmp2, fp); kvp = kvp->next; } fprintf(fp, "\n"); sp = sp->next; } fclose(fp); }
/** * @brief Initialize the cfile system. Called once at application start. * * @param exe_dir Path to a file (not a directory) * @param cdrom_dir Path to a CD drive mount point (may be NULL) * * @return 0 On success * @return 1 On error */ int cfile_init(const char *exe_dir, const char *cdrom_dir) { // initialize encryption encrypt_init(); if (cfile_inited) { return 0; } char buf[CFILE_ROOT_DIRECTORY_LEN]; strncpy(buf, exe_dir, CFILE_ROOT_DIRECTORY_LEN - 1); buf[CFILE_ROOT_DIRECTORY_LEN - 1] = '\0'; size_t i = strlen(buf); // are we in a root directory? if(cfile_in_root_dir(buf)){ os::dialogs::Message(os::dialogs::MESSAGEBOX_ERROR, "FreeSpace2/Fred2 cannot be run from a drive root directory!"); return 1; } // This needs to be set here because cf_build_secondary_filelist assumes it to be true cfile_inited = 1; /* * Determine the executable's directory. Note that DIR_SEPARATOR_CHAR * is guaranteed to be found in the string else cfile_in_root_dir() * would have failed. */ char *p; p = strrchr(buf, DIR_SEPARATOR_CHAR); *p = '\0'; cfile_chdir(buf); // set root directory strncpy(Cfile_root_dir, buf, CFILE_ROOT_DIRECTORY_LEN-1); strncpy(Cfile_user_dir, os_get_config_path().c_str(), CFILE_ROOT_DIRECTORY_LEN-1); #ifdef SCP_UNIX // Initialize path of old pilot files extern const char* Osreg_user_dir_legacy; snprintf(Cfile_user_dir_legacy, CFILE_ROOT_DIRECTORY_LEN-1, "%s/%s/", getenv("HOME"), Osreg_user_dir_legacy); #endif for (i = 0; i < MAX_CFILE_BLOCKS; i++) { Cfile_block_list[i].type = CFILE_BLOCK_UNUSED; } // 32 bit CRC table init cf_chksum_long_init(); Cfile_cdrom_dir = cdrom_dir; cf_build_secondary_filelist(Cfile_cdrom_dir); return 0; }
void add_default_module_paths(void) { char bin[512]; char data[512]; int ret; for (int i = 0; i < module_patterns_size; i++) obs_add_module_path(module_bin[i], module_data[i]); ret = os_get_config_path(bin, sizeof(bin), "obs-plugins/%module%"); if (ret <= 0) return; strcpy(data, bin); strcat(data, "/data"); strcat(bin, "/bin"); obs_add_module_path(bin, data); }
static Profile *profile_read(const char *file) { FILE *fp = NULL; char *str; if (os_is_legacy_mode()) { #ifdef WIN32 return nullptr; // No config file in legacy mode #else // Try to use the config file at the old location char legacy_path[MAX_PATH_LEN]; snprintf(legacy_path, MAX_PATH_LEN, "%s/%s/%s", getenv("HOME"), Osreg_user_dir_legacy, file); fp = fopen(legacy_path, "rt"); #endif } else { fp = fopen(os_get_config_path(file).c_str(), "rt"); } if (fp == NULL) return NULL; Profile *profile = (Profile *)vm_malloc(sizeof(Profile)); profile->sections = NULL; Section **sp_ptr = &(profile->sections); Section *sp = NULL; KeyValue **kvp_ptr = NULL; while ((str = read_line_from_file(fp)) != NULL) { char *ptr = trim_string(str); if (*ptr == '[') { ptr++; char *pend = strchr(ptr, ']'); if (pend != NULL) { // if (pend[1]) { /* trailing garbage! */ } *pend = 0; if (*ptr) { sp = (Section *)vm_malloc(sizeof(Section)); sp->next = NULL; sp->name = vm_strdup(ptr); sp->pairs = NULL; *sp_ptr = sp; sp_ptr = &(sp->next); kvp_ptr = &(sp->pairs); } // else { /* null name! */ } } // else { /* incomplete section name! */ } } else { if (*ptr) { char *key = ptr; char *value = NULL; ptr = strchr(ptr, '='); if (ptr != NULL) { *ptr = 0; ptr++; value = ptr; } // else { /* random garbage! */ } if (key && *key && value /* && *value */) { if (sp != NULL) { KeyValue *kvp = (KeyValue *)vm_malloc(sizeof(KeyValue)); kvp->key = vm_strdup(key); kvp->value = vm_strdup(value); kvp->next = NULL; *kvp_ptr = kvp; kvp_ptr = &(kvp->next); } // else { /* key/value with no section! */ } // else { /* malformed key/value entry! */ } } // else it's just a comment or empty string } vm_free(str); } fclose(fp); return profile; }