style cleanyp
[blender.git] / intern / ghost / intern / GHOST_SystemPathsX11.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2010 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file ghost/intern/GHOST_SystemPathsX11.cpp
28  *  \ingroup GHOST
29  */
30
31
32 #include "GHOST_SystemPathsX11.h"
33
34 #include "GHOST_Debug.h"
35
36 // For timing
37
38 #include <sys/time.h>
39 #include <unistd.h>
40
41 #include <stdio.h> // for fprintf only
42 #include <cstdlib> // for exit
43
44 #include <pwd.h> // for get home without use getenv()
45 #include <limits.h> // for PATH_MAX
46
47 #ifdef PREFIX
48 static const char *static_path = PREFIX "/share";
49 #else
50 static const char *static_path = NULL;
51 #endif
52
53 GHOST_SystemPathsX11::GHOST_SystemPathsX11()
54 {
55 }
56
57 GHOST_SystemPathsX11::~GHOST_SystemPathsX11()
58 {
59 }
60
61 const GHOST_TUns8 *GHOST_SystemPathsX11::getSystemDir(int, const char *versionstr) const
62 {
63         /* no prefix assumes a portable build which only uses bundled scripts */
64         if (static_path) {
65                 static char system_path[PATH_MAX];
66                 snprintf(system_path, sizeof(system_path), "%s/blender/%s", static_path, versionstr);
67                 return (GHOST_TUns8*)system_path;
68         }
69
70         return NULL;
71 }
72
73 const GHOST_TUns8 *GHOST_SystemPathsX11::getUserDir(int version, const char *versionstr) const
74 {
75         static char user_path[PATH_MAX];
76
77         /* in blender 2.64, we migrate to XDG. to ensure the copy previous settings
78          * operator works we give a different path depending on the requested version */
79         if (version < 264) {
80                 const char *home = getenv("HOME");
81
82                 if (home) {
83                         snprintf(user_path, sizeof(user_path), "%s/.blender/%s", home, versionstr);
84                         return (GHOST_TUns8*)user_path;
85                 }
86
87                 return NULL;
88         }
89         else {
90                 const char *home= getenv("XDG_CONFIG_HOME");
91
92                 if (home) {
93                         snprintf(user_path, sizeof(user_path), "%s/blender/%s", home, versionstr);
94                 }
95                 else {
96                         home= getenv("HOME");
97
98                         if (home == NULL)
99                                 home= getpwuid(getuid())->pw_dir;
100
101                         snprintf(user_path, sizeof(user_path), "%s/.config/blender/%s", home, versionstr);
102                 }
103
104                 return (const GHOST_TUns8 *)user_path;
105         }
106 }
107
108 const GHOST_TUns8 *GHOST_SystemPathsX11::getBinaryDir() const
109 {
110         return NULL;
111 }
112
113 void GHOST_SystemPathsX11::addToSystemRecentFiles(const char *filename) const
114 {
115         /* XXXXX TODO: Implementation for X11 if possible */
116
117 }