Merge branch 'blender2.7'
[blender.git] / intern / ghost / intern / GHOST_SystemPathsWin32.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) 2011 Blender Foundation.
19  * All rights reserved.
20  *
21  * Contributor(s): Blender Foundation
22  *                 Andrea Weikert
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file ghost/intern/GHOST_SystemPathsWin32.cpp
28  *  \ingroup GHOST
29  */
30
31
32 #include "GHOST_SystemPathsWin32.h"
33
34 #ifndef _WIN32_IE
35 #define _WIN32_IE 0x0501
36 #endif
37 #include <shlobj.h>
38 #include "utfconv.h"
39
40 GHOST_SystemPathsWin32::GHOST_SystemPathsWin32()
41 {
42 }
43
44 GHOST_SystemPathsWin32::~GHOST_SystemPathsWin32()
45 {
46 }
47
48 const GHOST_TUns8 *GHOST_SystemPathsWin32::getSystemDir(int, const char *versionstr) const
49 {
50         static char knownpath[MAX_PATH * 3 + 128] = {0}; /* 1 utf-16 might translante into 3 utf-8. 2 utf-16 translates into 4 utf-8*/
51         wchar_t knownpath_16[MAX_PATH];
52
53         HRESULT hResult = SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16);
54
55         if (hResult == S_OK) {
56                 conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3);
57                 strcat(knownpath, "\\Blender Foundation\\Blender\\");
58                 strcat(knownpath, versionstr);
59                 return (GHOST_TUns8*)knownpath;
60         }
61
62         return NULL;
63 }
64
65 const GHOST_TUns8 *GHOST_SystemPathsWin32::getUserDir(int, const char *versionstr) const
66 {
67         static char knownpath[MAX_PATH * 3 + 128] = {0};
68         wchar_t knownpath_16[MAX_PATH];
69
70         HRESULT hResult = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16);
71
72         if (hResult == S_OK) {
73                 conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3);
74                 strcat(knownpath, "\\Blender Foundation\\Blender\\");
75                 strcat(knownpath, versionstr);
76                 return (GHOST_TUns8*)knownpath;
77         }
78
79         return NULL;
80 }
81
82 const GHOST_TUns8 *GHOST_SystemPathsWin32::getBinaryDir() const
83 {
84         static char fullname[MAX_PATH * 3] = {0};
85         wchar_t fullname_16[MAX_PATH * 3];
86
87         if (GetModuleFileNameW(0, fullname_16, MAX_PATH)) {
88                 conv_utf_16_to_8(fullname_16, fullname, MAX_PATH * 3);
89                 return (GHOST_TUns8 *)fullname;
90         }
91
92         return NULL;
93 }
94
95 void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char *filename) const
96 {
97         /* SHARD_PATH resolves to SHARD_PATHA for non-UNICODE build */
98         UTF16_ENCODE(filename);
99         SHAddToRecentDocs(SHARD_PATHW, filename_16);
100         UTF16_UN_ENCODE(filename);
101 }