1
//============================================================================
5
// SS tttttt eeee ll ll aaaa
6
// SSSS tt ee ee ll ll aa
7
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8
// SS SS tt ee ll ll aa aa
9
// SSSS ttt eeeee llll llll aaaaa
11
// Copyright (c) 1995-2010 by Bradford W. Mott, Stephen Anthony
12
// and the Stella Team
14
// See the file "License.txt" for information on usage and redistribution of
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
17
// $Id: HomeFinder.hxx 2001 2010-04-10 21:37:23Z stephena $
18
//============================================================================
20
#ifndef __HOME_FINDER_
21
#define __HOME_FINDER_
26
* Used to determine the location of the 'HOME' and 'APPDATA' folders.
28
* Win98 and earlier don't have SHGetFolderPath in shell32.dll.
29
* Microsoft recommend that we load shfolder.dll at run time and
30
* access the function through that.
32
* shfolder.dll is loaded dynamically in the constructor, and unloaded in
35
* The class makes SHGetFolderPath available through its function operator.
36
* It will work on all versions of Windows >= Win95.
38
* This code was borrowed from the Lyx project.
43
HomeFinder() : myFolderModule(0), myFolderPathFunc(0)
45
myFolderModule = LoadLibrary("shfolder.dll");
47
myFolderPathFunc = reinterpret_cast<function_pointer>
48
(::GetProcAddress(myFolderModule, "SHGetFolderPathA"));
51
~HomeFinder() { if(myFolderModule) FreeLibrary(myFolderModule); }
53
/** Wrapper for SHGetFolderPathA, returning the 'HOME/User' folder
54
(or an empty string if the folder couldn't be determined. */
55
string getHomePath() const
57
if(!myFolderPathFunc) return "";
58
char folder_path[MAX_PATH];
59
HRESULT const result = (myFolderPathFunc)
60
(NULL, CSIDL_PROFILE | CSIDL_FLAG_CREATE, NULL, 0, folder_path);
62
return (result == 0) ? folder_path : "";
65
/** Wrapper for SHGetFolderPathA, returning the 'APPDATA' folder
66
(or an empty string if the folder couldn't be determined. */
67
string getAppDataPath() const
69
if(!myFolderPathFunc) return "";
70
char folder_path[MAX_PATH];
71
HRESULT const result = (myFolderPathFunc)
72
(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, folder_path);
74
return (result == 0) ? folder_path : "";
78
typedef HRESULT (__stdcall * function_pointer)(HWND, int, HANDLE, DWORD, LPCSTR);
80
HMODULE myFolderModule;
81
function_pointer myFolderPathFunc;