Line | |
---|
1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | using namespace Jenga::Common;
|
---|
4 |
|
---|
5 | Directory::Directory( const std::string &path, bool isMake )
|
---|
6 | : path( path )
|
---|
7 | {
|
---|
8 | if ( isMake )
|
---|
9 | {
|
---|
10 | if (!::MakeSureDirectoryPathExists(path.c_str()))
|
---|
11 | {
|
---|
12 | Jenga::Throw( "MakeSureDirectoryPathExists failed!" );
|
---|
13 | }
|
---|
14 | }
|
---|
15 | }
|
---|
16 |
|
---|
17 | std::string Directory::GetFullPath( const std::string &relationPath )
|
---|
18 | {
|
---|
19 | std::string resultPath = relationPath;
|
---|
20 |
|
---|
21 | // '/'→'\'
|
---|
22 | BOOST_FOREACH( char &c, resultPath )
|
---|
23 | {
|
---|
24 | if( c == '/' )
|
---|
25 | {
|
---|
26 | c = '\\';
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | if( resultPath.find( ":" ) != std::string::npos || resultPath.find( "\\\\" ) != std::string::npos )
|
---|
31 | {
|
---|
32 | // フルパスが引き渡されていたとき
|
---|
33 | return resultPath;
|
---|
34 | }
|
---|
35 |
|
---|
36 | int i=0,i2=0;
|
---|
37 | while(1){
|
---|
38 | if(resultPath[i]=='.'&&resultPath[i+1]=='\\') i+=2;
|
---|
39 | if(resultPath[i]=='.'&&resultPath[i+1]=='.'&&resultPath[i+2]=='\\'){
|
---|
40 | i2++;
|
---|
41 | i+=3;
|
---|
42 | }
|
---|
43 | else break;
|
---|
44 | }
|
---|
45 |
|
---|
46 | int i3 = (int)path.size(),i4=0;
|
---|
47 | while(i4<i2){
|
---|
48 | for(i3--;;i3--){
|
---|
49 | if(path[i3-1]=='\\'){
|
---|
50 | i4++;
|
---|
51 | break;
|
---|
52 | }
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | char temporary[MAX_PATH];
|
---|
57 | memcpy(temporary,path.c_str(),i3);
|
---|
58 | temporary[i3]=0;
|
---|
59 | lstrcat(temporary,resultPath.c_str()+i);
|
---|
60 |
|
---|
61 | return temporary;
|
---|
62 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.