source: dev/trunk/ab5.0/jenga/src/common/Path.cpp@ 477

Last change on this file since 477 was 477, checked in by dai_9181, 16 years ago

構成管理を大幅に改良。

File size: 1.6 KB
Line 
1#include <boost/foreach.hpp>
2#include <jenga/include/common/Path.h>
3
4#include <windows.h>
5
6
7bool Jenga::Common::Path::IsExistFile() const
8{
9 WIN32_FIND_DATA wfd;
10 HANDLE hFind = FindFirstFile( fullPath.c_str() , &wfd );
11 if( hFind != INVALID_HANDLE_VALUE ){
12 FindClose( hFind );
13 if( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
14 {
15 // ディレクトリ
16 return false;
17 }
18
19 return true;
20 }
21
22 return false;
23}
24
25std::string Jenga::Common::Path::MakeFullPath( const std::string &relativePath, const std::string &baseDirPath )
26{
27 int i,i2,i3,i4;
28 char temporary[MAX_PATH];
29
30 char resultPath[MAX_PATH];
31 lstrcpy( resultPath, relativePath.c_str() );
32
33 // '/'→'\'
34 for( i=0;resultPath[i];i++ ){
35 if( resultPath[i] == '/' ){
36 resultPath[i]='\\';
37 }
38 }
39
40 if(strstr(resultPath,":")||strstr(resultPath,"\\\\")) return resultPath;
41
42 i=0;i2=0;
43 while(1){
44 if(resultPath[i]=='.'&&resultPath[i+1]=='\\') i+=2;
45 if(resultPath[i]=='.'&&resultPath[i+1]=='.'&&resultPath[i+2]=='\\'){
46 i2++;
47 i+=3;
48 }
49 else break;
50 }
51
52 std::string tempBaseDirPath = baseDirPath;
53 if( tempBaseDirPath[tempBaseDirPath.size()-1] != '\\' )
54 {
55 tempBaseDirPath += "\\";
56 }
57
58 i3=(int)tempBaseDirPath.size();i4=0;
59 while(i4<i2){
60 for(i3--;;i3--){
61 if(tempBaseDirPath[i3-1]=='\\'){
62 i4++;
63 break;
64 }
65 }
66 }
67 memcpy(temporary,tempBaseDirPath.c_str(),i3);
68 temporary[i3]=0;
69 lstrcat(temporary,resultPath+i);
70 lstrcpy(resultPath,temporary);
71
72 if( resultPath[lstrlen(resultPath)-1] == '\\' )
73 {
74 resultPath[lstrlen(resultPath)-1] = 0;
75 }
76
77 return resultPath;
78}
Note: See TracBrowser for help on using the repository browser.