~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/win32/HomeFinder.hxx

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Kitt
  • Date: 2010-07-12 23:49:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100712234936-juawrr3etzhr2qpv
Tags: 3.1.2-1
* New maintainer (closes: #532039).
* New upstream version (closes: #461121):
  - includes launcher (closes: #396058).
* Fix the reference to the X Window System in the description (closes:
  #411815).
* Move to main, DFSG-free ROMs are available (see README.Debian).
* Enhance the package description.
* Drop the libslang2-dev dependency (closes: #560274).
* Remove the Encoding entry from stella.desktop.
* Avoid ignoring errors when cleaning.
* Add ${misc:Depends} to the package dependencies.
* Provide a doc-base file to install the documentation using doc-base.
* Switch to debhelper 7 with a simplified rules file.
* Use autotools-dev to provide updated configuration files.
* Update to Standards-Version 3.9.0:
  - Move to menu section Applications/Emulators.
  - Move the homepage declaration.
* Re-write the manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//============================================================================
 
2
//
 
3
//   SSSS    tt          lll  lll       
 
4
//  SS  SS   tt           ll   ll        
 
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
 
10
//
 
11
// Copyright (c) 1995-2010 by Bradford W. Mott, Stephen Anthony
 
12
// and the Stella Team
 
13
//
 
14
// See the file "License.txt" for information on usage and redistribution of
 
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
16
//
 
17
// $Id: HomeFinder.hxx 2001 2010-04-10 21:37:23Z stephena $
 
18
//============================================================================
 
19
 
 
20
#ifndef __HOME_FINDER_
 
21
#define __HOME_FINDER_
 
22
 
 
23
#include <shlobj.h>
 
24
 
 
25
/*
 
26
 * Used to determine the location of the 'HOME' and 'APPDATA' folders.
 
27
 *
 
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.
 
31
 *
 
32
 * shfolder.dll is loaded dynamically in the constructor, and unloaded in
 
33
 * the destructor
 
34
 *
 
35
 * The class makes SHGetFolderPath available through its function operator.
 
36
 * It will work on all versions of Windows >= Win95.
 
37
 *
 
38
 * This code was borrowed from the Lyx project.
 
39
 */
 
40
class HomeFinder
 
41
{
 
42
  public:
 
43
    HomeFinder() : myFolderModule(0), myFolderPathFunc(0)
 
44
    {
 
45
      myFolderModule = LoadLibrary("shfolder.dll");
 
46
      if(myFolderModule)
 
47
        myFolderPathFunc = reinterpret_cast<function_pointer>
 
48
           (::GetProcAddress(myFolderModule, "SHGetFolderPathA"));
 
49
    }
 
50
 
 
51
    ~HomeFinder() { if(myFolderModule) FreeLibrary(myFolderModule); }
 
52
 
 
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
 
56
    {
 
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);
 
61
 
 
62
      return (result == 0) ? folder_path : "";
 
63
    }
 
64
 
 
65
    /** Wrapper for SHGetFolderPathA, returning the 'APPDATA' folder
 
66
        (or an empty string if the folder couldn't be determined. */
 
67
    string getAppDataPath() const
 
68
    {
 
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);
 
73
 
 
74
      return (result == 0) ? folder_path : "";
 
75
    }
 
76
 
 
77
    private:
 
78
      typedef HRESULT (__stdcall * function_pointer)(HWND, int, HANDLE, DWORD, LPCSTR);
 
79
 
 
80
      HMODULE myFolderModule;
 
81
      function_pointer myFolderPathFunc;
 
82
};
 
83
 
 
84
#endif