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

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

構成管理を大幅に改良。

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