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