~ubuntu-branches/ubuntu/trusty/libsdl2/trusty-proposed

« back to all changes in this revision

Viewing changes to src/filesystem/windows/SDL_sysfilesystem.c

  • Committer: Package Import Robot
  • Author(s): Manuel A. Fernandez Montecelo
  • Date: 2013-12-28 12:31:19 UTC
  • mto: (7.1.3 sid)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: package-import@ubuntu.com-20131228123119-wehupm72qsjvh6vz
Tags: upstream-2.0.1+dfsg1
ImportĀ upstreamĀ versionĀ 2.0.1+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Simple DirectMedia Layer
 
3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
 
4
 
 
5
  This software is provided 'as-is', without any express or implied
 
6
  warranty.  In no event will the authors be held liable for any damages
 
7
  arising from the use of this software.
 
8
 
 
9
  Permission is granted to anyone to use this software for any purpose,
 
10
  including commercial applications, and to alter it and redistribute it
 
11
  freely, subject to the following restrictions:
 
12
 
 
13
  1. The origin of this software must not be misrepresented; you must not
 
14
     claim that you wrote the original software. If you use this software
 
15
     in a product, an acknowledgment in the product documentation would be
 
16
     appreciated but is not required.
 
17
  2. Altered source versions must be plainly marked as such, and must not be
 
18
     misrepresented as being the original software.
 
19
  3. This notice may not be removed or altered from any source distribution.
 
20
*/
 
21
#include "SDL_config.h"
 
22
 
 
23
#ifdef SDL_FILESYSTEM_WINDOWS
 
24
 
 
25
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
26
/* System dependent filesystem routines                                */
 
27
 
 
28
#include "../../core/windows/SDL_windows.h"
 
29
#include <shlobj.h>
 
30
 
 
31
#include "SDL_assert.h"
 
32
#include "SDL_error.h"
 
33
#include "SDL_stdinc.h"
 
34
#include "SDL_filesystem.h"
 
35
 
 
36
char *
 
37
SDL_GetBasePath(void)
 
38
{
 
39
    TCHAR path[MAX_PATH];
 
40
    const DWORD len = GetModuleFileName(NULL, path, SDL_arraysize(path));
 
41
    size_t i;
 
42
 
 
43
    SDL_assert(len < SDL_arraysize(path));
 
44
 
 
45
    if (len == 0) {
 
46
        WIN_SetError("Couldn't locate our .exe");
 
47
        return NULL;
 
48
    }
 
49
 
 
50
    for (i = len-1; i > 0; i--) {
 
51
        if (path[i] == '\\') {
 
52
            break;
 
53
        }
 
54
    }
 
55
 
 
56
    SDL_assert(i > 0); /* Should have been an absolute path. */
 
57
    path[i+1] = '\0';  /* chop off filename. */
 
58
    return WIN_StringToUTF8(path);
 
59
}
 
60
 
 
61
char *
 
62
SDL_GetPrefPath(const char *org, const char *app)
 
63
{
 
64
    /*
 
65
     * Vista and later has a new API for this, but SHGetFolderPath works there,
 
66
     *  and apparently just wraps the new API. This is the new way to do it:
 
67
     *
 
68
     *     SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
 
69
     *                          NULL, &wszPath);
 
70
     */
 
71
 
 
72
    TCHAR path[MAX_PATH];
 
73
    char *utf8 = NULL;
 
74
    char *retval = NULL;
 
75
 
 
76
    if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, path))) {
 
77
        WIN_SetError("Couldn't locate our prefpath");
 
78
        return NULL;
 
79
    }
 
80
 
 
81
    utf8 = WIN_StringToUTF8(path);
 
82
    if (utf8) {
 
83
        const size_t len = SDL_strlen(utf8) + SDL_strlen(org) + SDL_strlen(app) + 4;
 
84
        retval = (char *) SDL_malloc(len);
 
85
        if (!retval) {
 
86
            SDL_free(utf8);
 
87
            SDL_OutOfMemory();
 
88
            return NULL;
 
89
        }
 
90
        SDL_snprintf(retval, len, "%s\\%s\\%s\\", utf8, org, app);
 
91
        SDL_free(utf8);
 
92
    }
 
93
 
 
94
    return retval;
 
95
}
 
96
 
 
97
#endif /* SDL_FILESYSTEM_WINDOWS */
 
98
 
 
99
/* vi: set ts=4 sw=4 expandtab: */