int settings_file_commit(SettingsFile *sf) { OsTempFile tmp_file; int err = os_create_temp_file(os_path_dirname(sf->path).raw(), &tmp_file); if (err) return err; FILE *f = tmp_file.file; int indent = 0; json_line_comment(f, indent, "Genesis DAW configuration file"); json_line_comment(f, indent, "This config file format is a superset of JSON. See"); json_line_comment(f, indent, "https://github.com/andrewrk/liblaxjson for more details."); json_line_comment(f, indent, "WARNING: This file is sporadically overwritten while Genesis is running."); do_indent(f, indent); json_line_indent(f, &indent, "{"); json_line_comment(f, indent, "your display name"); json_line_str(f, indent, "user_name", sf->user_name.encode()); fprintf(f, "\n"); json_line_comment(f, indent, "your user id"); json_line_uint256(f, indent, "user_id", sf->user_id); fprintf(f, "\n"); json_line_comment(f, indent, "extra directories to search for samples."); json_line_comment(f, indent, "note: ~/.genesis/samples/ is always searched."); json_line_str_list(f, indent, "sample_dirs", sf->sample_dirs); fprintf(f, "\n"); json_line_comment(f, indent, "open this project on startup"); json_line_uint256(f, indent, "open_project_id", sf->open_project_id); fprintf(f, "\n"); json_line_comment(f, indent, "these perspectives are available for the user to choose from"); json_line_perspectives(f, indent, "perspectives", sf->perspectives); fprintf(f, "\n"); json_line_comment(f, indent, "open these windows on startup"); json_line_open_windows(f, indent, "open_windows", sf->open_windows); fprintf(f, "\n"); json_line_comment(f, indent, "how many seconds long should audio buffers be"); json_line_comment(f, indent, "a shorter value makes genesis respond to events faster"); json_line_comment(f, indent, "a larger value guards against buffer underruns"); json_line_double(f, indent, "latency", sf->latency); fprintf(f, "\n"); json_line_outdent(f, &indent, "}"); if (fclose(f)) return GenesisErrorFileAccess; err = os_rename_clobber(tmp_file.path.raw(), sf->path.raw()); if (err) return err; return 0; }
int os_mkdirp(ByteBuffer path) { struct stat st; int err = stat(path.raw(), &st); if (!err && S_ISDIR(st.st_mode)) return 0; err = mkdir(path.raw(), default_dir_mode); if (!err) return 0; if (errno != ENOENT) return GenesisErrorFileAccess; ByteBuffer dirname = os_path_dirname(path); err = os_mkdirp(dirname); if (err) return err; return os_mkdirp(path); }