doxygen: add newline after \file
[blender.git] / intern / ghost / intern / GHOST_SystemPathsWin32.cpp
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2011 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup GHOST
22  */
23
24
25 #include "GHOST_SystemPathsWin32.h"
26
27 #ifndef _WIN32_IE
28 #define _WIN32_IE 0x0501
29 #endif
30 #include <shlobj.h>
31 #include "utfconv.h"
32
33 GHOST_SystemPathsWin32::GHOST_SystemPathsWin32()
34 {
35 }
36
37 GHOST_SystemPathsWin32::~GHOST_SystemPathsWin32()
38 {
39 }
40
41 const GHOST_TUns8 *GHOST_SystemPathsWin32::getSystemDir(int, const char *versionstr) const
42 {
43         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*/
44         wchar_t knownpath_16[MAX_PATH];
45
46         HRESULT hResult = SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16);
47
48         if (hResult == S_OK) {
49                 conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3);
50                 strcat(knownpath, "\\Blender Foundation\\Blender\\");
51                 strcat(knownpath, versionstr);
52                 return (GHOST_TUns8*)knownpath;
53         }
54
55         return NULL;
56 }
57
58 const GHOST_TUns8 *GHOST_SystemPathsWin32::getUserDir(int, const char *versionstr) const
59 {
60         static char knownpath[MAX_PATH * 3 + 128] = {0};
61         wchar_t knownpath_16[MAX_PATH];
62
63         HRESULT hResult = SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath_16);
64
65         if (hResult == S_OK) {
66                 conv_utf_16_to_8(knownpath_16, knownpath, MAX_PATH * 3);
67                 strcat(knownpath, "\\Blender Foundation\\Blender\\");
68                 strcat(knownpath, versionstr);
69                 return (GHOST_TUns8*)knownpath;
70         }
71
72         return NULL;
73 }
74
75 const GHOST_TUns8 *GHOST_SystemPathsWin32::getBinaryDir() const
76 {
77         static char fullname[MAX_PATH * 3] = {0};
78         wchar_t fullname_16[MAX_PATH * 3];
79
80         if (GetModuleFileNameW(0, fullname_16, MAX_PATH)) {
81                 conv_utf_16_to_8(fullname_16, fullname, MAX_PATH * 3);
82                 return (GHOST_TUns8 *)fullname;
83         }
84
85         return NULL;
86 }
87
88 void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char *filename) const
89 {
90         /* SHARD_PATH resolves to SHARD_PATHA for non-UNICODE build */
91         UTF16_ENCODE(filename);
92         SHAddToRecentDocs(SHARD_PATHW, filename_16);
93         UTF16_UN_ENCODE(filename);
94 }