source: dev/trunk/jenga/src/common/Directory.cpp@ 343

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