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