Changeset View
Changeset View
Standalone View
Standalone View
source/blender/datatoc/datatoc_icon.c
| Show First 20 Lines • Show All 302 Lines • ▼ Show 20 Lines | static bool icon_merge(const char *file_src, | ||||
| (void)canvas_h; | (void)canvas_h; | ||||
| return true; | return true; | ||||
| } | } | ||||
| static bool icondir_to_png(const char *path_src, const char *file_dst) | static bool icondir_to_png(const char *path_src, const char *file_dst) | ||||
| { | { | ||||
| /* Takes a path full of 'dat' files and writes out */ | /* Takes a path full of 'dat' files and writes out */ | ||||
| DIR *dir; | struct dirent **namelist; | ||||
| int dirn; | |||||
| const struct dirent *fname; | const struct dirent *fname; | ||||
| char filepath[1024]; | char filepath[1024]; | ||||
| char *filename; | char *filename; | ||||
| int path_str_len; | int path_str_len; | ||||
| int found = 0, fail = 0; | int found = 0, fail = 0; | ||||
| unsigned int *pixels_canvas = NULL; | unsigned int *pixels_canvas = NULL; | ||||
| unsigned int canvas_w = 0, canvas_h = 0; | unsigned int canvas_w = 0, canvas_h = 0; | ||||
| errno = 0; | errno = 0; | ||||
| dir = opendir(path_src); | dirn = scandir(path_src, &namelist, NULL, alphasort); | ||||
| if (dir == NULL) { | if (dirn == -1) { | ||||
| printf( | printf( | ||||
| "%s: failed to dir '%s', (%s)\n", __func__, path_src, errno ? strerror(errno) : "unknown"); | "%s: failed to dir '%s', (%s)\n", __func__, path_src, errno ? strerror(errno) : "unknown"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| strcpy(filepath, path_src); | strcpy(filepath, path_src); | ||||
| path_str_len = path_ensure_slash(filepath); | path_str_len = path_ensure_slash(filepath); | ||||
| filename = &filepath[path_str_len]; | filename = &filepath[path_str_len]; | ||||
| while ((fname = readdir(dir)) != NULL) { | while (dirn--) { | ||||
| fname = namelist[dirn]; | |||||
| if (path_test_extension(fname->d_name, ".dat")) { | if (path_test_extension(fname->d_name, ".dat")) { | ||||
| strcpy(filename, fname->d_name); | strcpy(filename, fname->d_name); | ||||
| if (icon_merge(filepath, &pixels_canvas, &canvas_w, &canvas_h)) { | if (icon_merge(filepath, &pixels_canvas, &canvas_w, &canvas_h)) { | ||||
| found++; | found++; | ||||
| } | } | ||||
| else { | else { | ||||
| fail++; | fail++; | ||||
| } | } | ||||
| } | } | ||||
| free(fname); | |||||
| } | } | ||||
| closedir(dir); | free(namelist); | ||||
| if (found == 0) { | if (found == 0) { | ||||
| printf("%s: dir '%s' has no icons\n", __func__, path_src); | printf("%s: dir '%s' has no icons\n", __func__, path_src); | ||||
| } | } | ||||
| if (fail != 0) { | if (fail != 0) { | ||||
| printf("%s: dir '%s' failed %d icons\n", __func__, path_src, fail); | printf("%s: dir '%s' failed %d icons\n", __func__, path_src, fail); | ||||
| } | } | ||||
| Show All 27 Lines | |||||