diff --git a/inc/hgl/filesystem/EnumFile.h b/inc/hgl/filesystem/EnumFile.h index 2f5b683..009634a 100644 --- a/inc/hgl/filesystem/EnumFile.h +++ b/inc/hgl/filesystem/EnumFile.h @@ -60,7 +60,7 @@ namespace hgl virtual EnumFileConfig *CreateSubConfig(struct EnumFileConfig *up_efc,const FileInfo &fi) { - const OSString full_sub_folder_name=MergeFilename(up_efc->folder_name,fi.name); + const OSString full_sub_folder_name=Combine(up_efc->folder_name,fi.name); return(new EnumFileConfig(up_efc,full_sub_folder_name)); } diff --git a/inc/hgl/filesystem/Filename.h b/inc/hgl/filesystem/Filename.h index 5fcad35..2981624 100644 --- a/inc/hgl/filesystem/Filename.h +++ b/inc/hgl/filesystem/Filename.h @@ -31,7 +31,7 @@ namespace hgl * 根据离散的每一级目录名称和最终名称合成完整文件名 */ template - inline const String ComboFilename(T **str_list,int *str_len,const int count,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR) + inline const String Combine(T **str_list,int *str_len,const int count,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR) { T *fullname=nullptr; @@ -73,19 +73,143 @@ namespace hgl return String::newOf(fullname,p-fullname); } + template + inline const String Combine(const T spear_char,const T *str1,ARGS...args) + { + const int count=sizeof...(ARGS); + + if(count<=0) + return String(str1); + + int total_len=hgl::strlen(str1); + AutoDeleteArray str_len[count+1]; + + str_len[0]=total_len; + + { + int index=1; + for(const T *str:args) + { + str_len[index]=hgl::strlen(str); + total+=str_len[index]+1; + ++index; + } + } + + T *fullname=new T[total]; + T *p=fullname; + + hgl_cpy(p,str1,str_len[0]); + p+=str_len[0]; + + { + int index=1; + for(const T *str:args) + { + *p=spear_char; + ++p; + hgl_cpy(p,str,str_len[index]) + p+=str_len[index]; + } + + fullename[total-1]=0; + } + + return String::newOf(fullname,total-1); + } + + template + inline const String Combine(const char *str1,ARGS...args) + { + return Combine(HGL_DIRECTORY_SEPARATOR_RAWCHAR,str1,args...); + } + + #ifdef HGL_SUPPORT_CHAR8_T + template + inline const String Combine(const char8_t *str1,ARGS...args) + { + return Combine(HGL_DIRECTORY_SEPARATOR_U8CHAR,str1,args...); + } + #endif//HGL_SUPPORT_CHAR8_T + + #if HGL_OS == HGL_OS_Windows + template + inline const String Combine(const wchar_t *str1,ARGS...args) + { + return Combine(HGL_DIRECTORY_SEPARATOR_WCHAR,str1,args...); + } + #endif//HGL_OS == HGL_OS_Windows + + template + inline const String Combine(const T spear_char,const String &str1,ARGS...args) + { + const int count=sizeof...(ARGS); + + if(count<=0) + return str1; + + int total_len=str1.Length() + + for(const String &str:args) + total+=str.Length()+1; + + T *fullname=new T[total]; + T *p=fullname; + + hgl_cpy(p,str1.c_str(),str1.Length()); + p+=str1.Length(); + + { + int index=1; + for(const String &str:args) + { + *p=spear_char; + ++p; + hgl_cpy(p,str.c_str(),str.Length()) + p+=str1.Length(); + } + + fullename[total-1]=0; + } + + return String::newOf(fullname,total-1); + } + + template + inline const String Combine(const String &str1,ARGS...args) + { + return Combine(HGL_DIRECTORY_SEPARATOR_RAWCHAR,str1,args...); + } + + #ifdef HGL_SUPPORT_CHAR8_T + template + inline const String Combine(const String &str1,ARGS...args) + { + return Combine(HGL_DIRECTORY_SEPARATOR_U8CHAR,str1,args...); + } + #endif//HGL_SUPPORT_CHAR8_T + + #if HGL_OS == HGL_OS_Windows + template + inline const String Combine(const String &str1,ARGS...args) + { + return Combine(HGL_DIRECTORY_SEPARATOR_WCHAR,str1,args...); + } + #endif//HGL_OS == HGL_OS_Windows + /** * 组合文件名.
* 根据离散的每一级目录名称和最终名称合成完整文件名 */ template - inline const String ComboFilename(T **str_list,const int count,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR) + inline const String Combine(T **str_list,const int count,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR) { int str_len[count]; for(int i=0;i - inline const String ComboFilename(const StringList &sl,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR) + inline const String Combine(const StringList &sl,const T spear_char=(T)HGL_DIRECTORY_SEPARATOR_RAWCHAR) { const int count=sl.GetCount(); @@ -116,7 +240,7 @@ namespace hgl ++index; } - return ComboFilename(str_list.data(),str_len,count,spear_char); + return Combine(str_list.data(),str_len,count,spear_char); } /** @@ -124,7 +248,7 @@ namespace hgl * 根据路径名和文件名 */ template - inline String MergeFilename(const String &pathname,const String &filename,const T directory_separator_char,const T *directory_separator_str) + inline String Combine(const String &pathname,const String &filename,const T directory_separator_char,const T *directory_separator_str) { String fullname; @@ -369,16 +493,16 @@ namespace hgl } #ifdef HGL_SUPPORT_CHAR8_T - inline AnsiString MergeFilename(const AnsiString &pathname,const AnsiString &filename) ///<组合路径名与文件名 - {return MergeFilename(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_RAWSTR);} + inline AnsiString Combine(const AnsiString &pathname,const AnsiString &filename) ///<组合路径名与文件名 + {return Combine(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_RAWSTR);} #endif//HGL_SUPPORT_CHAR8_T - inline U8String MergeFilename(const U8String &pathname,const U8String &filename) ///<组合路径名与文件名 - {return MergeFilename(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_U8STR);} + inline U8String Combine(const U8String &pathname,const U8String &filename) ///<组合路径名与文件名 + {return Combine(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_U8STR);} #if HGL_OS == HGL_OS_Windows - inline WString MergeFilename(const WString &pathname,const WString &filename) ///<组合路径名与文件名 - {return MergeFilename(pathname,filename,L'\\',L"\\");} + inline WString Combine(const WString &pathname,const WString &filename) ///<组合路径名与文件名 + {return Combine(pathname,filename,HGL_DIRECTORY_SEPARATOR,HGL_DIRECTORY_SEPARATOR_STR);} #endif//HGL_OS == HGL_OS_Windows OSString FixFilename(const OSString &filename); ///<修正部分文件名问题 diff --git a/inc/hgl/platform/os/MSWindows.h b/inc/hgl/platform/os/MSWindows.h index befbc04..12b0a98 100644 --- a/inc/hgl/platform/os/MSWindows.h +++ b/inc/hgl/platform/os/MSWindows.h @@ -38,6 +38,8 @@ using os_char =wchar_t; #define HGL_PLUGIN_FUNC extern "C" __declspec(dllexport) //插件函数定义 #define HGL_DIRECTORY_SEPARATOR_RAWCHAR '\\' //目录分隔符 +#define HGL_DIRECTORY_SEPARATOR_U8CHAR U8_TEXT('\\') //目录分隔符 +#define HGL_DIRECTORY_SEPARATOR_WCHAR U16_TEXT('\\') //目录分隔符 #define HGL_DIRECTORY_SEPARATOR_RAWSTR "\\" //目录分隔符 #define HGL_DIRECTORY_SEPARATOR OS_TEXT('\\') //目录分隔符 #define HGL_DIRECTORY_SEPARATOR_STR OS_TEXT("\\") //目录分隔符 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3eab261..d618d29 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -208,7 +208,9 @@ SET(FILESYSTEM_INCLUDE_PATH ${CMCORE_ROOT_INCLUDE_PATH}/hgl/filesystem) SET(FILESYSTEM_HEADER_FILES ${FILESYSTEM_INCLUDE_PATH}/EnumFile.h ${FILESYSTEM_INCLUDE_PATH}/EnumVolume.h - ${FILESYSTEM_INCLUDE_PATH}/FileSystem.h) + ${FILESYSTEM_INCLUDE_PATH}/FileSystem.h + ${FILESYSTEM_INCLUDE_PATH}/Filename.h +) SET(FILESYSTEM_SOURCE_FILES FileSystem/FileSystem.cpp FileSystem/EnumFile.cpp) diff --git a/src/FileSystem/FileSystem.cpp b/src/FileSystem/FileSystem.cpp index 0a92936..3a2665d 100644 --- a/src/FileSystem/FileSystem.cpp +++ b/src/FileSystem/FileSystem.cpp @@ -397,7 +397,7 @@ namespace hgl for(const OSString *pn:paths) { - full_filename=MergeFilename(*pn,filename); + full_filename=Combine(*pn,filename); exist=FileExist(full_filename); @@ -431,7 +431,7 @@ namespace hgl { for(const OSString *fn:filenames) { - full_filename=MergeFilename(*pn,*fn); + full_filename=Combine(*pn,*fn); exist=FileExist(full_filename); diff --git a/src/Log/LogFile.cpp b/src/Log/LogFile.cpp index a2e5a17..2c5b9f3 100644 --- a/src/Log/LogFile.cpp +++ b/src/Log/LogFile.cpp @@ -41,12 +41,12 @@ namespace hgl if(!GetLocalAppdataPath(local_app_data_path)) return(false); - cmgdk_path=filesystem::MergeFilename(local_app_data_path,OS_TEXT(".cmgdk")); + cmgdk_path=filesystem::Combine(local_app_data_path,OS_TEXT(".cmgdk")); if(!filesystem::MakePath(cmgdk_path)) return(false); - fn=filesystem::MergeFilename(cmgdk_path,project_code); + fn=filesystem::Combine(cmgdk_path,project_code); for(uint i=0;i<=0xFFFF;i++) { diff --git a/src/PlugIn/PlugInManage.cpp b/src/PlugIn/PlugInManage.cpp index 0b6a512..0835e1a 100644 --- a/src/PlugIn/PlugInManage.cpp +++ b/src/PlugIn/PlugInManage.cpp @@ -15,7 +15,7 @@ namespace hgl { AddFindPath(pn); - pn=MergeFilename(pn,OS_TEXT("Plug-ins")); + pn=Combine(pn,OS_TEXT("Plug-ins")); AddFindPath(pn); } @@ -23,7 +23,7 @@ namespace hgl { AddFindPath(pn); - pn=MergeFilename(pn,OS_TEXT("Plug-ins")); + pn=Combine(pn,OS_TEXT("Plug-ins")); AddFindPath(pn); } } @@ -105,7 +105,7 @@ namespace hgl for(uint i=0;i