Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_files.c
| Context not available. | |||||
| win->sizey = oldwin->sizey; | win->sizey = oldwin->sizey; | ||||
| win->posx = oldwin->posx; | win->posx = oldwin->posx; | ||||
| win->posy = oldwin->posy; | win->posy = oldwin->posy; | ||||
| win->ghost_rect = oldwin->ghost_rect; | |||||
| } | } | ||||
| static void wm_window_match_keep_current_wm( | static void wm_window_match_keep_current_wm( | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| /* read a user config file and return all lines | |||||
| * returned lines must be freed by the caller with BLI_file_free_lines() */ | |||||
| static LinkNode *wm_user_file_read_lines(const char *filename) | |||||
| { | |||||
| char name[FILE_MAX]; | |||||
| const char * const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL); | |||||
| if (!cfgdir) return NULL; | |||||
| BLI_make_file_string("/", name, cfgdir, filename); | |||||
| return BLI_file_read_as_lines(name); | |||||
| } | |||||
| /* open a user config file with the give mode */ | |||||
| static FILE *wm_user_file_open(const char *filename, const char *mode) | |||||
| { | |||||
| const char *user_config_dir; | |||||
| char name[FILE_MAX]; | |||||
| /* will be NULL in background mode */ | |||||
| user_config_dir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL); | |||||
| if (!user_config_dir) | |||||
| return NULL; | |||||
| BLI_make_file_string("/", name, user_config_dir, filename); | |||||
| return BLI_fopen(name, mode); | |||||
| } | |||||
| /** \name WM window position File API | |||||
| * \{ */ | |||||
| void wm_window_positions_file_read(struct ListBase *windowpos) | |||||
| { | |||||
| LinkNode *l, *lines; | |||||
| wmWindowPosition *pos; | |||||
| const char *line; | |||||
| lines = wm_user_file_read_lines(BLENDER_WINDOWS_FILE); | |||||
| if (lines == NULL) | |||||
| return; | |||||
| BLI_listbase_clear(windowpos); | |||||
| /* read list of window positions */ | |||||
| for (l = lines; l; l = l->next) { | |||||
| line = l->link; | |||||
| if (line[0]) { | |||||
| pos = (wmWindowPosition *)MEM_mallocN(sizeof(wmWindowPosition), "wmWindowPosition"); | |||||
| sscanf(line, "%d %d %d %d %d %d", &pos->type, &pos->windowstate, | |||||
| &pos->rect.xmin, &pos->rect.ymin, | |||||
| &pos->rect.xmax, &pos->rect.ymax); | |||||
| BLI_addtail(windowpos, pos); | |||||
| } | |||||
| } | |||||
| BLI_file_free_lines(lines); | |||||
| } | |||||
| /** | |||||
| * Write window positions to disk | |||||
| */ | |||||
| void wm_window_positions_file_write(ListBase *windowpos) | |||||
| { | |||||
| FILE *fp = wm_user_file_open(BLENDER_WINDOWS_FILE, "w"); | |||||
| if (fp) { | |||||
| struct wmWindowPosition *pos; | |||||
| for (pos = windowpos->first; pos; pos = pos->next) { | |||||
| fprintf(fp, "%d %d %d %d %d %d\n", pos->type, pos->windowstate, | |||||
| pos->rect.xmin, pos->rect.ymin, | |||||
| pos->rect.xmax, pos->rect.ymax); | |||||
| } | |||||
| fclose(fp); | |||||
| } | |||||
| } | |||||
| /** \name WM History File API | /** \name WM History File API | ||||
| * \{ */ | * \{ */ | ||||
| void wm_history_file_read(void) | void wm_history_file_read(void) | ||||
| { | { | ||||
| char name[FILE_MAX]; | |||||
| LinkNode *l, *lines; | LinkNode *l, *lines; | ||||
| struct RecentFile *recent; | struct RecentFile *recent; | ||||
| const char *line; | const char *line; | ||||
| int num; | int num; | ||||
| const char * const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL); | |||||
| if (!cfgdir) return; | lines = wm_user_file_read_lines(BLENDER_HISTORY_FILE); | ||||
| if (lines == NULL) | |||||
| BLI_make_file_string("/", name, cfgdir, BLENDER_HISTORY_FILE); | return; | ||||
| lines = BLI_file_read_as_lines(name); | |||||
| BLI_listbase_clear(&G.recent_files); | BLI_listbase_clear(&G.recent_files); | ||||
| Context not available. | |||||
| */ | */ | ||||
| static void wm_history_file_write(void) | static void wm_history_file_write(void) | ||||
| { | { | ||||
| const char *user_config_dir; | FILE *fp = wm_user_file_open(BLENDER_HISTORY_FILE, "w"); | ||||
| char name[FILE_MAX]; | |||||
| FILE *fp; | |||||
| /* will be NULL in background mode */ | |||||
| user_config_dir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL); | |||||
| if (!user_config_dir) | |||||
| return; | |||||
| BLI_make_file_string("/", name, user_config_dir, BLENDER_HISTORY_FILE); | |||||
| fp = BLI_fopen(name, "w"); | |||||
| if (fp) { | if (fp) { | ||||
| struct RecentFile *recent; | struct RecentFile *recent; | ||||
| for (recent = G.recent_files.first; recent; recent = recent->next) { | for (recent = G.recent_files.first; recent; recent = recent->next) { | ||||
| Context not available. | |||||