Debian Codegraph @

src/file/dirs_win32.c

raw
1 /*
2 * This file is part of libbluray
3 * Copyright (C) 2011 VideoLAN
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library 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 GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see
17 * <http://www.gnu.org/licenses/>.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #endif
23
24 #include "dirs.h"
25
26 #include "util/logging.h"
27
28 #include <stdio.h>
29 #include <string.h>
30
31 #include <windows.h>
32 #include <shlobj.h>
33 #include <limits.h>
34
35
36 int win32_mkdir(const char *dir)
37 {
38 wchar_t wdir[MAX_PATH];
39
40 MultiByteToWideChar(CP_UTF8, 0, dir, -1, wdir, MAX_PATH);
41
42 if (!CreateDirectoryW(wdir, NULL))
43 return -1;
44 return 0;
45 }
46
47 char *file_get_config_home(void)
48 {
49 return file_get_data_home();
50 }
51
52 char *file_get_data_home(void)
53 {
54 wchar_t wdir[MAX_PATH];
55
56 /* Get the "Application Data" folder for the user */
57 if (S_OK == SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
58 NULL, SHGFP_TYPE_CURRENT, wdir)) {
59 int len = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL);
60 char *appdir = malloc(len);
61 if (appdir) {
62 WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL);
63 }
64 return appdir;
65 }
66
67 BD_DEBUG(DBG_FILE, "Can't find user configuration directory !\n");
68 return NULL;
69 }
70
71 char *file_get_cache_home(void)
72 {
73 return file_get_data_home();
74 }
75
76 const char *file_get_config_system(const char *dir)
77 {
78 static char *appdir = NULL;
79 wchar_t wdir[MAX_PATH];
80
81 if (!dir) {
82 // first call
83
84 if (appdir)
85 return appdir;
86
87 /* Get the "Application Data" folder for all users */
88 if (S_OK == SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE,
89 NULL, SHGFP_TYPE_CURRENT, wdir)) {
90 int len = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL);
91 appdir = malloc(len);
92 if (appdir) {
93 WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL);
94 }
95 return appdir;
96 } else {
97 BD_DEBUG(DBG_FILE, "Can't find common configuration directory !\n");
98 return NULL;
99 }
100 } else {
101 // next call
102 return NULL;
103 }
104
105 return dir;
106 }