diff --git a/CMakeCache.txt b/CMakeCache.txt new file mode 100644 index 0000000..afc40f7 --- /dev/null +++ b/CMakeCache.txt @@ -0,0 +1,351 @@ +# This is the CMakeCache file. +# For build in directory: d:/data/code/WinUtils +# It was generated by CMake: D:/apps/cmake/bin/cmake.exe +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + +//The directory containing a CMake configuration file for Boost. +Boost_DIR:PATH=Boost_DIR-NOTFOUND + +//Path to a file. +Boost_INCLUDE_DIR:PATH=Boost_INCLUDE_DIR-NOTFOUND + +//Path to a program. +CMAKE_AR:FILEPATH=D:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/lib.exe + +//Semicolon separated list of supported configuration types, only +// supports Debug, Release, MinSizeRel, and RelWithDebInfo, anything +// else will be ignored. +CMAKE_CONFIGURATION_TYPES:STRING=Debug;Release;MinSizeRel;RelWithDebInfo + +//Flags used by the CXX compiler during all build types. +CMAKE_CXX_FLAGS:STRING=/DWIN32 /D_WINDOWS /W3 /GR /EHsc + +//Flags used by the CXX compiler during DEBUG builds. +CMAKE_CXX_FLAGS_DEBUG:STRING=/MDd /Zi /Ob0 /Od /RTC1 + +//Flags used by the CXX compiler during MINSIZEREL builds. +CMAKE_CXX_FLAGS_MINSIZEREL:STRING=/MD /O1 /Ob1 /DNDEBUG + +//Flags used by the CXX compiler during RELEASE builds. +CMAKE_CXX_FLAGS_RELEASE:STRING=/MD /O2 /Ob2 /DNDEBUG + +//Flags used by the CXX compiler during RELWITHDEBINFO builds. +CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=/MD /Zi /O2 /Ob1 /DNDEBUG + +//Libraries linked by default with all C++ applications. +CMAKE_CXX_STANDARD_LIBRARIES:STRING=kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib + +//Flags used by the C compiler during all build types. +CMAKE_C_FLAGS:STRING=/DWIN32 /D_WINDOWS /W3 + +//Flags used by the C compiler during DEBUG builds. +CMAKE_C_FLAGS_DEBUG:STRING=/MDd /Zi /Ob0 /Od /RTC1 + +//Flags used by the C compiler during MINSIZEREL builds. +CMAKE_C_FLAGS_MINSIZEREL:STRING=/MD /O1 /Ob1 /DNDEBUG + +//Flags used by the C compiler during RELEASE builds. +CMAKE_C_FLAGS_RELEASE:STRING=/MD /O2 /Ob2 /DNDEBUG + +//Flags used by the C compiler during RELWITHDEBINFO builds. +CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=/MD /Zi /O2 /Ob1 /DNDEBUG + +//Libraries linked by default with all C applications. +CMAKE_C_STANDARD_LIBRARIES:STRING=kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib + +//Flags used by the linker during all build types. +CMAKE_EXE_LINKER_FLAGS:STRING=/machine:x64 + +//Flags used by the linker during DEBUG builds. +CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=/debug /INCREMENTAL + +//Flags used by the linker during MINSIZEREL builds. +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=/INCREMENTAL:NO + +//Flags used by the linker during RELEASE builds. +CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=/INCREMENTAL:NO + +//Flags used by the linker during RELWITHDEBINFO builds. +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=/debug /INCREMENTAL + +//Value Computed by CMake. +CMAKE_FIND_PACKAGE_REDIRECTS_DIR:STATIC=D:/data/code/WinUtils/CMakeFiles/pkgRedirects + +//Install path prefix, prepended onto install directories. +CMAKE_INSTALL_PREFIX:PATH=C:/Program Files (x86)/WinUtils + +//Path to a program. +CMAKE_LINKER:FILEPATH=D:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/link.exe + +//Flags used by the linker during the creation of modules during +// all build types. +CMAKE_MODULE_LINKER_FLAGS:STRING=/machine:x64 + +//Flags used by the linker during the creation of modules during +// DEBUG builds. +CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING=/debug /INCREMENTAL + +//Flags used by the linker during the creation of modules during +// MINSIZEREL builds. +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING=/INCREMENTAL:NO + +//Flags used by the linker during the creation of modules during +// RELEASE builds. +CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING=/INCREMENTAL:NO + +//Flags used by the linker during the creation of modules during +// RELWITHDEBINFO builds. +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING=/debug /INCREMENTAL + +//Path to a program. +CMAKE_MT:FILEPATH=D:/Windows Kits/10/bin/10.0.22000.0/x64/mt.exe + +//Value Computed by CMake +CMAKE_PROJECT_DESCRIPTION:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_HOMEPAGE_URL:STATIC=https://github.com/zuijiuzhou/WinUtils + +//Value Computed by CMake +CMAKE_PROJECT_NAME:STATIC=WinUtils + +//Value Computed by CMake +CMAKE_PROJECT_VERSION:STATIC=1.0.0 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_MAJOR:STATIC=1 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_MINOR:STATIC=0 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_PATCH:STATIC=0 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_TWEAK:STATIC= + +//RC compiler +CMAKE_RC_COMPILER:FILEPATH=D:/Windows Kits/10/bin/10.0.22000.0/x64/rc.exe + +//Flags for Windows Resource Compiler during all build types. +CMAKE_RC_FLAGS:STRING=-DWIN32 + +//Flags for Windows Resource Compiler during DEBUG builds. +CMAKE_RC_FLAGS_DEBUG:STRING=-D_DEBUG + +//Flags for Windows Resource Compiler during MINSIZEREL builds. +CMAKE_RC_FLAGS_MINSIZEREL:STRING= + +//Flags for Windows Resource Compiler during RELEASE builds. +CMAKE_RC_FLAGS_RELEASE:STRING= + +//Flags for Windows Resource Compiler during RELWITHDEBINFO builds. +CMAKE_RC_FLAGS_RELWITHDEBINFO:STRING= + +//Flags used by the linker during the creation of shared libraries +// during all build types. +CMAKE_SHARED_LINKER_FLAGS:STRING=/machine:x64 + +//Flags used by the linker during the creation of shared libraries +// during DEBUG builds. +CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING=/debug /INCREMENTAL + +//Flags used by the linker during the creation of shared libraries +// during MINSIZEREL builds. +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING=/INCREMENTAL:NO + +//Flags used by the linker during the creation of shared libraries +// during RELEASE builds. +CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING=/INCREMENTAL:NO + +//Flags used by the linker during the creation of shared libraries +// during RELWITHDEBINFO builds. +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING=/debug /INCREMENTAL + +//If set, runtime paths are not added when installing shared libraries, +// but are added when building. +CMAKE_SKIP_INSTALL_RPATH:BOOL=NO + +//If set, runtime paths are not added when using shared libraries. +CMAKE_SKIP_RPATH:BOOL=NO + +//Flags used by the linker during the creation of static libraries +// during all build types. +CMAKE_STATIC_LINKER_FLAGS:STRING=/machine:x64 + +//Flags used by the linker during the creation of static libraries +// during DEBUG builds. +CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during the creation of static libraries +// during MINSIZEREL builds. +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during the creation of static libraries +// during RELEASE builds. +CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during the creation of static libraries +// during RELWITHDEBINFO builds. +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//If this value is on, makefiles will be generated without the +// .SILENT directive, and all commands will be echoed to the console +// during the make. This is useful for debugging only. With Visual +// Studio IDE projects all commands are done without /nologo. +CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE + +//Value Computed by CMake +WinUtils_BINARY_DIR:STATIC=D:/data/code/WinUtils + +//Value Computed by CMake +WinUtils_IS_TOP_LEVEL:STATIC=ON + +//Value Computed by CMake +WinUtils_SOURCE_DIR:STATIC=D:/data/code/WinUtils + + +######################## +# INTERNAL cache entries +######################## + +//ADVANCED property for variable: Boost_DIR +Boost_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_AR +CMAKE_AR-ADVANCED:INTERNAL=1 +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=d:/data/code/WinUtils +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=25 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=2 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=D:/apps/cmake/bin/cmake.exe +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=D:/apps/cmake/bin/cpack.exe +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=D:/apps/cmake/bin/ctest.exe +//ADVANCED property for variable: CMAKE_CXX_FLAGS +CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG +CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL +CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE +CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO +CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_STANDARD_LIBRARIES +CMAKE_CXX_STANDARD_LIBRARIES-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS +CMAKE_C_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG +CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL +CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE +CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO +CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_STANDARD_LIBRARIES +CMAKE_C_STANDARD_LIBRARIES-ADVANCED:INTERNAL=1 +//Executable file format +CMAKE_EXECUTABLE_FORMAT:INTERNAL=Unknown +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS +CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG +CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE +CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=Visual Studio 17 2022 +//Generator instance identifier. +CMAKE_GENERATOR_INSTANCE:INTERNAL=d:/Program Files/Microsoft Visual Studio/2022/Enterprise +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=D:/data/code/WinUtils +//ADVANCED property for variable: CMAKE_LINKER +CMAKE_LINKER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS +CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG +CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE +CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MT +CMAKE_MT-ADVANCED:INTERNAL=1 +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=3 +//Platform information initialized +CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 +//noop for ranlib +CMAKE_RANLIB:INTERNAL=: +//ADVANCED property for variable: CMAKE_RC_COMPILER +CMAKE_RC_COMPILER-ADVANCED:INTERNAL=1 +CMAKE_RC_COMPILER_WORKS:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RC_FLAGS +CMAKE_RC_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RC_FLAGS_DEBUG +CMAKE_RC_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RC_FLAGS_MINSIZEREL +CMAKE_RC_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RC_FLAGS_RELEASE +CMAKE_RC_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RC_FLAGS_RELWITHDEBINFO +CMAKE_RC_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=D:/apps/cmake/share/cmake-3.25 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS +CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG +CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE +CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH +CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_RPATH +CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS +CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG +CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE +CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE +CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1 + diff --git a/src/EnvVarEditor/clslogger.h b/src/EnvVarEditor/clslogger.h index d1606c9..67c477b 100644 --- a/src/EnvVarEditor/clslogger.h +++ b/src/EnvVarEditor/clslogger.h @@ -46,7 +46,7 @@ __TSTR_FUNC__ void clslog(const TStr &msg, MessageType type) } HANDLE hnd = GetStdHandle(output); SetConsoleTextAttribute(hnd, attr); - std::cout << typeName << tstr2String(msg) << std::endl; + std::cout << typeName << tstr_to_str(msg) << std::endl; SetConsoleTextAttribute(hnd, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); } diff --git a/src/EnvVarEditor/evarutil.h b/src/EnvVarEditor/evarutil.h index a196368..b9806de 100644 --- a/src/EnvVarEditor/evarutil.h +++ b/src/EnvVarEditor/evarutil.h @@ -5,15 +5,15 @@ #define __HKEY_GLOBAL_ENV__ "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment" #define __HKEY_USER_ENV__ "Environment" -__TSTR_FUNC__ TStr evGet(const TStr &name, bool global = false); -__TSTR_FUNC__ void evSet(const TStr &name, const TStr &val, DWORD valType = REG_SZ, bool global = false); +__TSTR_FUNC__ TStr evar(const TStr &name, bool global = false); +__TSTR_FUNC__ void evar_set(const TStr &name, const TStr &val, DWORD valType = REG_SZ, bool global = false); -__TSTR_FUNC__ TStr evGet(const TStr &name, bool global) +__TSTR_FUNC__ TStr evar(const TStr &name, bool global) { - TStr val = reg_str_value(global ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, string2TStr(global ? __HKEY_GLOBAL_ENV__ : __HKEY_USER_ENV__), name, 2048ul); + TStr val = reg_str_value(global ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, str_to_tstr(global ? __HKEY_GLOBAL_ENV__ : __HKEY_USER_ENV__), name, 2048ul); return val; } -__TSTR_FUNC__ void evSet(const TStr &name, const TStr &val, DWORD valType, bool global) +__TSTR_FUNC__ void evar_set(const TStr &name, const TStr &val, DWORD valType, bool global) { - reg_str_value_set(global ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, string2TStr(global ? __HKEY_GLOBAL_ENV__ : __HKEY_USER_ENV__), name, val, valType); + reg_str_value_set(global ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, str_to_tstr(global ? __HKEY_GLOBAL_ENV__ : __HKEY_USER_ENV__), name, val, valType); } \ No newline at end of file diff --git a/src/EnvVarEditor/fileutil.h b/src/EnvVarEditor/fileutil.h new file mode 100644 index 0000000..10b09fd --- /dev/null +++ b/src/EnvVarEditor/fileutil.h @@ -0,0 +1,74 @@ +#pragma once +#ifndef __FILE_UTIL_H__ +#define __FILE_UTIL_H__ +#include "strutil.h" +#include +#include + +TextEncoding file_encoding(FILE *pFile); + +TextEncoding file_encoding(FILE *pFile) +{ + assert(fseek(pFile, 0, SEEK_END) == 0); + size_t fileLen = ftell(pFile); + TextEncoding te; + if (fileLen == 0) + { + te = TE_UNKNOW; + } + else + { + assert(fseek(pFile, 0, SEEK_SET) == 0); + char buf[64] = {0}; + size_t bufLen = 64; + size_t readLen = fread(buf, sizeof(char), bufLen, pFile); + char c0 = buf[0], + c1 = buf[1], + c2 = buf[2]; + if (readLen >= 3 && c0 == 0xef && c1 == 0xbb && c2 == 0xbf) + { + te = TE_UTF8; + } + else if (readLen >= 2 && c0 == 0xff && c1 == 0xfe) + { + te = TE_UTF16_LE; + } + else if (readLen >= 2 && c0 == 0xfe && c1 == 0xff) + { + te = TE_UTF16_BE; + } + else + { + assert(fseek(pFile, 0, SEEK_SET) == 0); + size_t charIdx = 0; + while (ftell(pFile) < fileLen) + { + readLen = fread(buf, sizeof(char), bufLen, pFile); + charIdx = 0; + while (charIdx < readLen) + { + // ASC2 + if (buf[charIdx] < 0x80) + { + } + // 非UTF8 + else if (buf[charIdx] < 0xc0) + { + } + // 双字节UTF-8 + else if (buf[charIdx] < 0xe0) + { + // + if (charIdx == readLen - 1) + { + } + } + charIdx++; + } + } + } + te = TE_UNKNOW; + } + return te; +} +#endif \ No newline at end of file diff --git a/src/EnvVarEditor/main.cpp b/src/EnvVarEditor/main.cpp index a30ed17..9e0b404 100644 Binary files a/src/EnvVarEditor/main.cpp and b/src/EnvVarEditor/main.cpp differ diff --git a/src/EnvVarEditor/pathutil.h b/src/EnvVarEditor/pathutil.h index d0a94a4..35225b4 100644 --- a/src/EnvVarEditor/pathutil.h +++ b/src/EnvVarEditor/pathutil.h @@ -9,11 +9,11 @@ #define __PATH_SEPERATOR__ ";" -__PATH__FUNC__ std::vector pathSplit(const TStr &data); -__PATH__FUNC__ int pathCompare(const TStr &left, const TStr &right); -__PATH__FUNC__ TStr pathJoin(std::vector items); +__PATH__FUNC__ std::vector path_split(const TStr &data); +__PATH__FUNC__ int path_compare(const TStr &left, const TStr &right); +__PATH__FUNC__ TStr path_join(std::vector items); -__PATH__FUNC__ std::vector pathSplit(const TStr &data) +__PATH__FUNC__ std::vector path_split(const TStr &data) { // std::wcout << __FUNCTIONW__ << std::endl; std::basic_regex reg(__TSTR__(__PATH_SEPERATOR__)); @@ -21,7 +21,7 @@ __PATH__FUNC__ std::vector pathSplit(const TStr &data) std::vector items = std::vector(iter, std::regex_token_iterator()); return items; } -__PATH__FUNC__ int pathCompare(const TStr &left, const TStr &right) +__PATH__FUNC__ int path_compare(const TStr &left, const TStr &right) { TStr leftTemp = left; TStr rightTemp = right; @@ -29,15 +29,17 @@ __PATH__FUNC__ int pathCompare(const TStr &left, const TStr &right) TStr seperator_unix(__TSTR__("/")); TStr seperator_unix2(__TSTR__("//")); - tstrReplace(leftTemp, seperator_win, seperator_unix); - tstrReplace(leftTemp, seperator_unix2, seperator_unix); - tstrReplace(rightTemp, seperator_win, seperator_unix); - tstrReplace(rightTemp, seperator_unix2, seperator_unix); - int n = tstrCompareIgnoreCase(leftTemp, rightTemp); + tstr_replace(leftTemp, seperator_win, seperator_unix); + tstr_replace(leftTemp, seperator_unix2, seperator_unix); + tstr_replace(rightTemp, seperator_win, seperator_unix); + tstr_replace(rightTemp, seperator_unix2, seperator_unix); + leftTemp = tstr_trim_end(leftTemp, '/'); + rightTemp = tstr_trim_end(rightTemp, '/'); + int n = tstr_cmp_icase(leftTemp, rightTemp); return n; } -__PATH__FUNC__ TStr pathJoin(std::vector items) +__PATH__FUNC__ TStr path_join(std::vector items) { - return tstrJoin(items, __TSTR__(__PATH_SEPERATOR__)); + return tstr_join(items, __TSTR__(__PATH_SEPERATOR__)); } diff --git a/src/EnvVarEditor/regutil.h b/src/EnvVarEditor/regutil.h index 5a06905..67636a4 100644 --- a/src/EnvVarEditor/regutil.h +++ b/src/EnvVarEditor/regutil.h @@ -3,6 +3,7 @@ #include #include "strutil.h" +__TSTR_FUNC__ bool reg_key_exists(HKEY hkey, const TStr &subkey); __TSTR_FUNC__ bool reg_value_exists(HKEY hkey, const TStr &subkey, const TStr &name); __TSTR_FUNC__ TStr reg_str_value(HKEY hkey, const TStr &subkey, const TStr &name, DWORD maxlen = MAX_PATH); __TSTR_FUNC__ void reg_str_value_set(HKEY hkey, const TStr &subkey, const TStr &name, const TStr &val, DWORD valType = REG_SZ); @@ -11,8 +12,8 @@ __TSTR_FUNC__ bool reg_value_exists(HKEY hkey, const TStr &subkey, const TStr &n { HKEY hk_sub; LSTATUS lret; - std::wstring wsubkey = tstr2Wstring(subkey); - std::wstring wname = tstr2Wstring(name); + std::wstring wsubkey = tstr_to_wstr(subkey); + std::wstring wname = tstr_to_wstr(name); if (ERROR_SUCCESS == (lret == RegOpenKeyEx(hkey, wsubkey.data(), 0, KEY_READ, &hk_sub))) { wchar_t szbuf[1] = {0}; @@ -31,8 +32,8 @@ __TSTR_FUNC__ TStr reg_str_value(HKEY hkey, const TStr &subkey, const TStr &name { HKEY hk_sub; LSTATUS lret; - std::wstring wsubkey = tstr2Wstring(subkey); - std::wstring wname = tstr2Wstring(name); + std::wstring wsubkey = tstr_to_wstr(subkey); + std::wstring wname = tstr_to_wstr(name); std::wstring result; if (ERROR_SUCCESS == (lret = RegOpenKeyEx(hkey, wsubkey.data(), 0, KEY_READ, &hk_sub))) { @@ -47,14 +48,14 @@ __TSTR_FUNC__ TStr reg_str_value(HKEY hkey, const TStr &subkey, const TStr &name delete[] szbuf; RegCloseKey(hk_sub); } - return wstring2TStr(result); + return tstr_to_wstr(result); } __TSTR_FUNC__ void reg_str_value_set(HKEY hkey, const TStr &subkey, const TStr &name, const TStr &val, DWORD valType) { LSTATUS lret; - std::wstring wsubkey = tstr2Wstring(subkey); - std::wstring wname = tstr2Wstring(name); - std::wstring wval = tstr2Wstring(val); + std::wstring wsubkey = tstr_to_wstr(subkey); + std::wstring wname = tstr_to_wstr(name); + std::wstring wval = tstr_to_wstr(val); if (ERROR_SUCCESS == (lret = RegSetKeyValue(hkey, wsubkey.data(), wname.data(), REG_SZ, wval.data(), wval.length() * sizeof(wchar_t)))) { diff --git a/src/EnvVarEditor/shutil.h b/src/EnvVarEditor/shutil.h index 3c932d9..3479a01 100644 --- a/src/EnvVarEditor/shutil.h +++ b/src/EnvVarEditor/shutil.h @@ -3,18 +3,18 @@ #include "pathutil.h" #include -__TSTR_FUNC__ int startAsAdmin(const TStr &exe, const TStr ¶ms); +__TSTR_FUNC__ int start_as_admin(const TStr &exe, const TStr ¶ms); -int restartAsAdmin(bool waitForExit = true); +int restart_as_admin(bool waitForExit = true); -__TSTR_FUNC__ int startAsAdmin(const TStr &exe, const TStr ¶ms) +__TSTR_FUNC__ int start_as_admin(const TStr &exe, const TStr ¶ms) { std::wstring wexe = tstr2Wstring(exe); std::wstring wparams = tstr2Wstring(params); return 0; } -int restartAsAdmin(bool waitForExit) +int restart_as_admin(bool waitForExit) { TCHAR exe[MAX_PATH]; ZeroMemory(exe, MAX_PATH); diff --git a/src/EnvVarEditor/strutil.h b/src/EnvVarEditor/strutil.h index 1d70b86..55be6c8 100644 Binary files a/src/EnvVarEditor/strutil.h and b/src/EnvVarEditor/strutil.h differ