Fixed issue with Win95/98 not having a required function which is required to determine the 'My Documents' folder. This issue was actually causing Stella not to start at all in those environments. Thanks to the Lyx project for the relevant code.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1484 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2008-04-26 16:51:13 +00:00
parent 74362c3f0f
commit bdedb60d9d
2 changed files with 96 additions and 8 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: OSystemWin32.cxx,v 1.23 2008-03-09 20:38:44 stephena Exp $
// $Id: OSystemWin32.cxx,v 1.24 2008-04-26 16:51:13 stephena Exp $
//============================================================================
#include <sstream>
@ -55,12 +55,15 @@ OSystemWin32::OSystemWin32()
This function is guaranteed to return a valid 'My Documents'
folder (as much as Windows *can* make that guarantee)
*/
char configPath[256];
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE,
NULL, 0, configPath)))
try
{
strcat(configPath, "\\Stella");
basedir = configPath;
GetFolderPathWin32 win32FolderPath;
string path = win32FolderPath(GetFolderPathWin32::PERSONAL) + "\\Stella";
basedir = path;
}
catch(char* msg)
{
cerr << msg << endl;
}
}
@ -78,3 +81,50 @@ uInt32 OSystemWin32::getTicks()
{
return (uInt32) SDL_GetTicks() * 1000;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GetFolderPathWin32::GetFolderPathWin32()
: myFolderModule(0),
myFolderPathFunc(0)
{
myFolderModule = LoadLibrary("shfolder.dll");
if(!myFolderModule)
throw "ERROR: GetFolderPathWin32() failed; cannot determine \'My Documents\' folder";
myFolderPathFunc = reinterpret_cast<function_pointer>
(::GetProcAddress(myFolderModule, "SHGetFolderPathA"));
if(myFolderPathFunc == 0)
throw "ERROR: GetFolderPathWin32() failed; cannot determine \'My Documents\' folder";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GetFolderPathWin32::~GetFolderPathWin32()
{
if(myFolderModule)
FreeLibrary(myFolderModule);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Given a folder ID, returns the folder name.
string const GetFolderPathWin32::operator()(kFolderId _id) const
{
char folder_path[MAX_PATH];
int id = 0;
switch(_id)
{
case PERSONAL:
id = CSIDL_PERSONAL;
break;
case APPDATA:
id = CSIDL_APPDATA;
break;
default:
return "";
}
HRESULT const result =
(myFolderPathFunc)(NULL, id | CSIDL_FLAG_CREATE, NULL, 0, folder_path);
return (result == 0) ? folder_path : "";
}

View File

@ -13,19 +13,21 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: OSystemWin32.hxx,v 1.12 2008-02-06 13:45:24 stephena Exp $
// $Id: OSystemWin32.hxx,v 1.13 2008-04-26 16:51:13 stephena Exp $
//============================================================================
#ifndef OSYSTEM_WIN32_HXX
#define OSYSTEM_WIN32_HXX
#include <windows.h>
#include "bspf.hxx"
/**
This class defines Windows system specific settings.
@author Stephen Anthony
@version $Id: OSystemWin32.hxx,v 1.12 2008-02-06 13:45:24 stephena Exp $
@version $Id: OSystemWin32.hxx,v 1.13 2008-04-26 16:51:13 stephena Exp $
*/
class OSystemWin32 : public OSystem
{
@ -49,4 +51,40 @@ class OSystemWin32 : public OSystem
virtual uInt32 getTicks();
};
/**
Win98 and earlier don't have SHGetFolderPath in shell32.dll.
Microsoft recommend that we load shfolder.dll at run time and
access the function through that.
shfolder.dll is loaded dynamically in the constructor. If loading
fails or if the .dll is found not to contain SHGetFolderPathA then
the program exits immediately. Otherwise, the .dll is unloaded in
the destructor
The class makes SHGetFolderPath available through its function operator.
It will work on all versions of Windows >= Win95.
This code was borrowed from the Lyx project.
*/
class GetFolderPathWin32
{
public:
enum kFolderId {
PERSONAL, // CSIDL_PERSONAL
APPDATA // CSIDL_APPDATA
};
GetFolderPathWin32();
~GetFolderPathWin32();
/** Wrapper for SHGetFolderPathA, returning the path asscociated with id. */
string const operator()(kFolderId id) const;
private:
typedef HRESULT (__stdcall * function_pointer)(HWND, int, HANDLE, DWORD, LPCSTR);
HMODULE myFolderModule;
function_pointer myFolderPathFunc;
};
#endif