source: dev/trunk/ab5.0/jenga/include/common/Environment.h

Last change on this file was 829, checked in by イグトランス (egtra), 13 years ago

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain; charset=Shift_JIS
File size: 1.7 KB
Line 
1#include <string>
2#include <windows.h>
3#include <shlobj.h>
4
5#pragma once
6
7namespace Jenga{
8namespace Common{
9
10
11class Environment
12{
13public:
14 static const std::string GetCurrentDir()
15 {
16 char temp[MAX_PATH];
17 ::GetCurrentDirectory( MAX_PATH, temp );
18 return temp;
19 }
20
21 static const std::string &GetAppDir()
22 {
23 static std::string appDir;
24 if( appDir.empty() )
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 }
41
42 static const std::string &GetAppFileName()
43 {
44 static std::string appFileName;
45 if( appFileName.empty() )
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;
62 if( appFilePath.empty() )
63 {
64 char temporary[MAX_PATH];
65 GetModuleFileName(GetModuleHandle(0),temporary,MAX_PATH);
66
67 appFilePath = temporary;
68 }
69 return appFilePath;
70 }
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 }
92};
93
94
95}}
Note: See TracBrowser for help on using the repository browser.