[818] | 1 | #include <string>
|
---|
| 2 | #include <windows.h>
|
---|
| 3 | #include <shlobj.h>
|
---|
| 4 |
|
---|
[164] | 5 | #pragma once
|
---|
| 6 |
|
---|
| 7 | namespace Jenga{
|
---|
| 8 | namespace Common{
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | class Environment
|
---|
| 12 | {
|
---|
| 13 | public:
|
---|
[480] | 14 | static const std::string GetCurrentDir()
|
---|
| 15 | {
|
---|
| 16 | char temp[MAX_PATH];
|
---|
| 17 | ::GetCurrentDirectory( MAX_PATH, temp );
|
---|
| 18 | return temp;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
[164] | 21 | static const std::string &GetAppDir()
|
---|
| 22 | {
|
---|
| 23 | static std::string appDir;
|
---|
[718] | 24 | if( appDir.empty() )
|
---|
[164] | 25 | {
|
---|
| 26 | char temporary[MAX_PATH];
|
---|
| 27 | char temp2[MAX_PATH];
|
---|
| 28 | char temp3[MAX_PATH];
|
---|
| 29 | GetModuleFileName(GetModuleHandle(0),temporary,MAX_PATH);
|
---|
| 30 | _splitpath(temporary,temp2,temp3,NULL,NULL);
|
---|
| 31 | if( temp3[lstrlen(temp3)-1]=='\\' )
|
---|
| 32 | {
|
---|
| 33 | temp3[lstrlen(temp3)-1] = 0;
|
---|
| 34 | }
|
---|
| 35 | lstrcat(temp2,temp3);
|
---|
| 36 |
|
---|
| 37 | appDir = temp2;
|
---|
| 38 | }
|
---|
| 39 | return appDir;
|
---|
| 40 | }
|
---|
[477] | 41 |
|
---|
| 42 | static const std::string &GetAppFileName()
|
---|
| 43 | {
|
---|
| 44 | static std::string appFileName;
|
---|
[718] | 45 | if( appFileName.empty() )
|
---|
[477] | 46 | {
|
---|
| 47 | char temporary[MAX_PATH];
|
---|
| 48 | char temp2[MAX_PATH];
|
---|
| 49 | char temp3[MAX_PATH];
|
---|
| 50 | GetModuleFileName(GetModuleHandle(0),temporary,MAX_PATH);
|
---|
| 51 | _splitpath(temporary,NULL,NULL,temp2,temp3);
|
---|
| 52 | lstrcat(temp2,temp3);
|
---|
| 53 |
|
---|
| 54 | appFileName = temp2;
|
---|
| 55 | }
|
---|
| 56 | return appFileName;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | static const std::string &GetAppFilePath()
|
---|
| 60 | {
|
---|
| 61 | static std::string appFilePath;
|
---|
[718] | 62 | if( appFilePath.empty() )
|
---|
[477] | 63 | {
|
---|
| 64 | char temporary[MAX_PATH];
|
---|
| 65 | GetModuleFileName(GetModuleHandle(0),temporary,MAX_PATH);
|
---|
| 66 |
|
---|
| 67 | appFilePath = temporary;
|
---|
| 68 | }
|
---|
| 69 | return appFilePath;
|
---|
| 70 | }
|
---|
[718] | 71 |
|
---|
| 72 | static const std::string &GetUserAppDir()
|
---|
| 73 | {
|
---|
| 74 | static std::string userAppDir;
|
---|
| 75 | if( userAppDir.empty() )
|
---|
| 76 | {
|
---|
| 77 | char szDirPath[MAX_PATH];
|
---|
| 78 | if( SHGetSpecialFolderPath( NULL, szDirPath, CSIDL_APPDATA, TRUE ) == FALSE )
|
---|
| 79 | {
|
---|
| 80 | throw;
|
---|
| 81 | }
|
---|
| 82 | userAppDir = szDirPath;
|
---|
| 83 |
|
---|
| 84 | if( userAppDir[userAppDir.size()-1] == '\\' )
|
---|
| 85 | {
|
---|
| 86 | userAppDir = userAppDir.substr( 0, userAppDir.size() - 1 );
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | return userAppDir;
|
---|
| 91 | }
|
---|
[164] | 92 | };
|
---|
| 93 |
|
---|
| 94 |
|
---|
[205] | 95 | }}
|
---|