3 #include "base_directory.hpp"
15 static const BaseDirectory
* get_instance() {
17 m_instance
= new BaseDirectory();
22 const string
& home() const {return m_home
;}
23 const string
& xdg_data_home() const {return m_xdg_data_home
;}
24 const vector
<string
>& xdg_data_dirs() const {return m_xdg_data_dirs
;}
36 tmp
= getenv("XDG_DATA_DIRS");
38 m_xdg_data_home
= tmp
;
40 m_xdg_data_home
= m_home
+ "/.local/share";
43 tmp
= getenv("XDG_DATA_DIRS");
44 if(not tmp
) tmp
= "/usr/local/share:/usr/share";
47 while(not tmp2
.empty() and tmp2
[0] == ':') {
48 tmp2
= tmp2
.substr(1);
51 while(not tmp2
.empty() and tmp2
[tmp2
.size()-1] == ':') {
52 tmp2
= tmp2
.substr(0, tmp2
.size()-1);
55 m_xdg_data_dirs
.push_back(m_xdg_data_home
);
57 while(pos
!= string::npos
) {
58 size_t nextpos
= tmp2
.find(':', pos
);
59 if(nextpos
== string::npos
) {
60 m_xdg_data_dirs
.push_back(tmp2
.substr(pos
));
63 m_xdg_data_dirs
.push_back(tmp2
.substr(pos
, nextpos
-pos
));
70 string m_xdg_data_home
;
71 vector
<string
> m_xdg_data_dirs
;
72 static BaseDirectory
* m_instance
;
74 BaseDirectory
* BaseDirectory::m_instance
= 0;
77 static string xdg_data_home
;
78 static vector
<string
> xdg_data_dirs
;
81 load_first_data(const std::string
& resource
)
83 const BaseDirectory
& bd
= *(BaseDirectory::get_instance());
84 const vector
<string
>& xdg_data_dirs
= bd
.xdg_data_dirs();
86 for(int i
= 0; i
< int(xdg_data_dirs
.size()); ++i
) {
87 string res
= xdg_data_dirs
[i
] + "/" + resource
;
88 if(access(res
.c_str(), R_OK
) == 0) return res
;