1// Aseprite
2// Copyright (C) 2001-2015 David Capello
3//
4// This program is distributed under the terms of
5// the End-User License Agreement for Aseprite.
6
7#ifndef APP_PREF_OPTION_IO_H_INCLUDED
8#define APP_PREF_OPTION_IO_H_INCLUDED
9#pragma once
10
11#include "app/ini_file.h"
12#include "app/pref/option.h"
13
14namespace app {
15
16 // Load
17
18 template<typename T>
19 void load_option(Option<T>& opt) {
20 if (get_config_string(opt.section(), opt.id(), nullptr))
21 opt(get_config_value(opt.section(), opt.id(), opt.defaultValue()));
22 else
23 opt.setValueAndDefault(opt.defaultValue());
24 }
25
26 template<typename T>
27 void load_option_with_migration(Option<T>& opt, const char* oldSection, const char* oldName) {
28 if (get_config_string(oldSection, oldName, nullptr)) {
29 opt(get_config_value(oldSection, oldName, opt.defaultValue()));
30 del_config_value(oldSection, oldName);
31
32 opt.forceDirtyFlag();
33 }
34 else {
35 load_option<T>(opt);
36 }
37 }
38
39 // Save
40
41 template<typename T>
42 void save_option(Option<T>& opt) {
43 if (!opt.isDirty())
44 return;
45
46 set_config_value(opt.section(), opt.id(), opt());
47 opt.cleanDirtyFlag();
48 }
49
50} // namespace app
51
52#endif
53