synched with trunk at revision 34793
[blender.git] / intern / ghost / intern / GHOST_SystemPathsWin32.cpp
1 /**
2  * $Id: GHOST_SystemPathsWin32.cpp 34372 2011-01-17 19:39:25Z elubie $
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * The Original Code is Copyright (C) 2011 Blender Foundation.
20  * All rights reserved.
21  * 
22  * Contributor(s): Blender Foundation
23  *                 Andrea Weikert
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #include "GHOST_SystemPathsWin32.h"
29
30 #define WIN32_LEAN_AND_MEAN
31 #ifdef _WIN32_IE
32 #undef _WIN32_IE
33 #endif
34 #define _WIN32_IE 0x0501
35 #include <windows.h>
36 #include <shlobj.h>
37
38 #if defined(__MINGW32__) || defined(__CYGWIN__)
39
40 #if !defined(SHARD_PIDL)
41 #define SHARD_PIDL      0x00000001L
42 #endif
43
44 #if !defined(SHARD_PATHA)
45 #define SHARD_PATHA     0x00000002L
46 #endif
47
48 #if !defined(SHARD_PATHA)
49 #define SHARD_PATHW     0x00000003L
50 #endif
51
52 #if !defined(SHARD_PATH)
53 #ifdef UNICODE
54 #define SHARD_PATH  SHARD_PATHW
55 #else
56 #define SHARD_PATH  SHARD_PATHA
57 #endif
58 #endif
59
60 #endif
61
62 GHOST_SystemPathsWin32::GHOST_SystemPathsWin32()
63 {
64 }
65
66 GHOST_SystemPathsWin32::~GHOST_SystemPathsWin32()
67 {
68 }
69
70 const GHOST_TUns8* GHOST_SystemPathsWin32::getSystemDir() const
71 {
72         static char knownpath[MAX_PATH];
73         HRESULT hResult = SHGetFolderPath(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath);
74
75         if (hResult == S_OK)
76         {
77                 return (GHOST_TUns8*)knownpath;
78         }
79
80         return NULL;
81 }
82
83 const GHOST_TUns8* GHOST_SystemPathsWin32::getUserDir() const
84 {
85         static char knownpath[MAX_PATH];
86         HRESULT hResult = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, knownpath);
87
88         if (hResult == S_OK)
89         {
90                 return (GHOST_TUns8*)knownpath;
91         }
92
93         return NULL;
94 }
95
96 const GHOST_TUns8* GHOST_SystemPathsWin32::getBinaryDir() const
97 {
98         static char fullname[MAX_PATH];
99         if(GetModuleFileName(0, fullname, MAX_PATH)) {
100                 return (GHOST_TUns8*)fullname;
101         }
102
103         return NULL;
104 }
105
106 void GHOST_SystemPathsWin32::addToSystemRecentFiles(const char* filename) const
107 {
108         /* SHARD_PATH resolves to SHARD_PATHA for non-UNICODE build */
109         SHAddToRecentDocs(SHARD_PATH,filename);
110 }