本文整理汇总了C++中UTF8ToTStr函数的典型用法代码示例。如果您正苦于以下问题:C++ UTF8ToTStr函数的具体用法?C++ UTF8ToTStr怎么用?C++ UTF8ToTStr使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UTF8ToTStr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Rename
// renames file srcFilename to destFilename, returns true on success
bool Rename(const std::string &srcFilename, const std::string &destFilename)
{
INFO_LOG(COMMON, "Rename: %s --> %s",
srcFilename.c_str(), destFilename.c_str());
#ifdef _WIN32
auto sf = UTF8ToTStr(srcFilename);
auto df = UTF8ToTStr(destFilename);
// The Internet seems torn about whether ReplaceFile is atomic or not.
// Hopefully it's atomic enough...
if (ReplaceFile(df.c_str(), sf.c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS, nullptr, nullptr))
return true;
// Might have failed because the destination doesn't exist.
if (GetLastError() == ERROR_FILE_NOT_FOUND)
{
if (MoveFile(sf.c_str(), df.c_str()))
return true;
}
#else
if (rename(srcFilename.c_str(), destFilename.c_str()) == 0)
return true;
#endif
ERROR_LOG(COMMON, "Rename: failed %s --> %s: %s",
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
return false;
}
示例2: Close
bool IOFile::Open(const std::string& filename, const char openmode[])
{
Close();
#ifdef _WIN32
_tfopen_s(&m_file, UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str());
#else
m_file = fopen(filename.c_str(), openmode);
#endif
m_good = IsOpen();
return m_good;
}
示例3: DefaultMsgHandler
// Default non library dependent panic alert
bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int Style)
{
#ifdef _WIN32
int STYLE = MB_ICONINFORMATION;
if (Style == QUESTION) STYLE = MB_ICONQUESTION;
if (Style == WARNING) STYLE = MB_ICONWARNING;
return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(), STYLE | (yes_no ? MB_YESNO : MB_OK));
#else
printf("%s\n", text);
return true;
#endif
}
示例4: CreateDir
// Returns true if successful, or path already exists.
bool CreateDir(const std::string &path)
{
INFO_LOG(COMMON, "CreateDir: directory %s", path.c_str());
#ifdef _WIN32
if (::CreateDirectory(UTF8ToTStr(path).c_str(), NULL))
return true;
DWORD error = GetLastError();
if (error == ERROR_ALREADY_EXISTS)
{
WARN_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: already exists", path.c_str());
return true;
}
ERROR_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: %i", path.c_str(), error);
return false;
#else
if (mkdir(path.c_str(), 0755) == 0)
return true;
int err = errno;
if (err == EEXIST)
{
WARN_LOG(COMMON, "CreateDir: mkdir failed on %s: already exists", path.c_str());
return true;
}
ERROR_LOG(COMMON, "CreateDir: mkdir failed on %s: %s", path.c_str(), strerror(err));
return false;
#endif
}
示例5: GetSize
// Returns the size of filename (64bit)
u64 GetSize(const std::string &filename)
{
if (!Exists(filename))
{
WARN_LOG(COMMON, "GetSize: failed %s: No such file", filename.c_str());
return 0;
}
if (IsDirectory(filename))
{
WARN_LOG(COMMON, "GetSize: failed %s: is a directory", filename.c_str());
return 0;
}
struct stat64 buf;
#ifdef _WIN32
if (_tstat64(UTF8ToTStr(filename).c_str(), &buf) == 0)
#else
if (stat64(filename.c_str(), &buf) == 0)
#endif
{
DEBUG_LOG(COMMON, "GetSize: %s: %lld",
filename.c_str(), (long long)buf.st_size);
return buf.st_size;
}
ERROR_LOG(COMMON, "GetSize: Stat failed %s: %s",
filename.c_str(), GetLastErrorMsg());
return 0;
}
示例6: DeleteDir
// Deletes a directory filename, returns true on success
bool DeleteDir(const std::string& filename)
{
INFO_LOG(COMMON, "DeleteDir: directory %s", filename.c_str());
// check if a directory
if (!IsDirectory(filename))
{
ERROR_LOG(COMMON, "DeleteDir: Not a directory %s", filename.c_str());
return false;
}
#ifdef _WIN32
if (::RemoveDirectory(UTF8ToTStr(filename).c_str()))
return true;
ERROR_LOG(COMMON, "DeleteDir: RemoveDirectory failed on %s: %s", filename.c_str(),
GetLastErrorString().c_str());
#else
if (rmdir(filename.c_str()) == 0)
return true;
ERROR_LOG(COMMON, "DeleteDir: rmdir failed on %s: %s", filename.c_str(),
LastStrerrorString().c_str());
#endif
return false;
}
示例7: CreateFileMapping
void MemArena::GrabSHMSegment(size_t size)
{
#ifdef _WIN32
const std::string name = "dolphin-emu." + std::to_string(GetCurrentProcessId());
hMemoryMapping = CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0,
static_cast<DWORD>(size), UTF8ToTStr(name).c_str());
#elif defined(ANDROID)
fd = AshmemCreateFileMapping(("dolphin-emu." + std::to_string(getpid())).c_str(), size);
if (fd < 0)
{
NOTICE_LOG(MEMMAP, "Ashmem allocation failed");
return;
}
#else
const std::string file_name = "/dolphin-emu." + std::to_string(getpid());
fd = shm_open(file_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600);
if (fd == -1)
{
ERROR_LOG(MEMMAP, "shm_open failed: %s", strerror(errno));
return;
}
shm_unlink(file_name.c_str());
if (ftruncate(fd, size) < 0)
ERROR_LOG(MEMMAP, "Failed to allocate low memory space");
#endif
}
示例8: CopyDir
// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string& source_path, const std::string& dest_path, bool destructive)
{
if (source_path == dest_path)
return;
if (!Exists(source_path))
return;
if (!Exists(dest_path))
File::CreateFullPath(dest_path);
#ifdef _WIN32
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(UTF8ToTStr(source_path + "\\*").c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE)
{
FindClose(hFind);
return;
}
do
{
const std::string virtualName(TStrToUTF8(ffd.cFileName));
#else
DIR* dirp = opendir(source_path.c_str());
if (!dirp)
return;
while (dirent* result = readdir(dirp))
{
const std::string virtualName(result->d_name);
#endif
// check for "." and ".."
if (virtualName == "." || virtualName == "..")
continue;
std::string source = source_path + DIR_SEP + virtualName;
std::string dest = dest_path + DIR_SEP + virtualName;
if (IsDirectory(source))
{
if (!Exists(dest))
File::CreateFullPath(dest + DIR_SEP);
CopyDir(source, dest, destructive);
}
else if (!destructive && !Exists(dest))
{
Copy(source, dest);
}
else if (destructive)
{
Rename(source, dest);
}
#ifdef _WIN32
} while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
#else
}
closedir(dirp);
#endif
}
示例9: Copy
// copies file source_path to destination_path, returns true on success
bool Copy(const std::string& source_path, const std::string& destination_path)
{
INFO_LOG(COMMON, "Copy: %s --> %s", source_path.c_str(), destination_path.c_str());
#ifdef _WIN32
if (CopyFile(UTF8ToTStr(source_path).c_str(), UTF8ToTStr(destination_path).c_str(), FALSE))
return true;
ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s", source_path.c_str(), destination_path.c_str(),
GetLastErrorString().c_str());
return false;
#else
std::ifstream source{source_path, std::ios::binary};
std::ofstream destination{destination_path, std::ios::binary};
destination << source.rdbuf();
return source.good() && destination.good();
#endif
}
示例10: DefaultMsgHandler
// Default non library dependent panic alert
bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int Style)
{
#ifdef _WIN32
int STYLE = MB_ICONINFORMATION;
if (Style == QUESTION)
STYLE = MB_ICONQUESTION;
if (Style == WARNING)
STYLE = MB_ICONWARNING;
return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(),
STYLE | (yes_no ? MB_YESNO : MB_OK));
#else
fprintf(stderr, "%s\n", text);
// Return no to any question (which will in general crash the emulator)
return false;
#endif
}
示例11: CopyDir
// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string &source_path, const std::string &dest_path)
{
if (source_path == dest_path) return;
if (!File::Exists(source_path)) return;
if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);
#ifdef _WIN32
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(UTF8ToTStr(source_path + "\\*").c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE)
{
FindClose(hFind);
return;
}
do
{
const std::string virtualName(TStrToUTF8(ffd.cFileName));
#else
struct dirent dirent, *result = NULL;
DIR *dirp = opendir(source_path.c_str());
if (!dirp) return;
while (!readdir_r(dirp, &dirent, &result) && result)
{
const std::string virtualName(result->d_name);
#endif
// check for "." and ".."
if (virtualName == "." || virtualName == "..")
continue;
std::string source, dest;
source = source_path + virtualName;
dest = dest_path + virtualName;
if (IsDirectory(source))
{
source += '/';
dest += '/';
if (!File::Exists(dest)) File::CreateFullPath(dest);
CopyDir(source, dest);
}
else if (!File::Exists(dest)) File::Copy(source, dest);
#ifdef _WIN32
}
while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);
#else
}
closedir(dirp);
#endif
}
示例12: GetTempFilenameForAtomicWrite
std::string GetTempFilenameForAtomicWrite(const std::string &path)
{
std::string abs = path;
#ifdef _WIN32
TCHAR absbuf[MAX_PATH];
if (_tfullpath(absbuf, UTF8ToTStr(path).c_str(), MAX_PATH) != nullptr)
abs = TStrToUTF8(absbuf);
#else
char absbuf[PATH_MAX];
if (realpath(path.c_str(), absbuf) != nullptr)
abs = absbuf;
#endif
return abs + ".xxx";
}
示例13: RenameSync
bool RenameSync(const std::string &srcFilename, const std::string &destFilename)
{
if (!Rename(srcFilename, destFilename))
return false;
#ifdef _WIN32
int fd = _topen(UTF8ToTStr(srcFilename).c_str(), _O_RDONLY);
if (fd != -1)
{
_commit(fd);
close(fd);
}
#else
char *path = strdup(srcFilename.c_str());
FSyncPath(path);
FSyncPath(dirname(path));
free(path);
path = strdup(destFilename.c_str());
FSyncPath(dirname(path));
free(path);
#endif
return true;
}
示例14: Delete
// Deletes a given filename, return true on success
// Doesn't supports deleting a directory
bool Delete(const std::string& filename)
{
INFO_LOG(COMMON, "Delete: file %s", filename.c_str());
const FileInfo file_info(filename);
// Return true because we care about the file no
// being there, not the actual delete.
if (!file_info.Exists())
{
WARN_LOG(COMMON, "Delete: %s does not exist", filename.c_str());
return true;
}
// We can't delete a directory
if (file_info.IsDirectory())
{
WARN_LOG(COMMON, "Delete failed: %s is a directory", filename.c_str());
return false;
}
#ifdef _WIN32
if (!DeleteFile(UTF8ToTStr(filename).c_str()))
{
WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s", filename.c_str(),
GetLastErrorMsg().c_str());
return false;
}
#else
if (unlink(filename.c_str()) == -1)
{
WARN_LOG(COMMON, "Delete: unlink failed on %s: %s", filename.c_str(),
GetLastErrorMsg().c_str());
return false;
}
#endif
return true;
}
示例15: AllocConsole
// 100, 100, "Dolphin Log Console"
// Open console window - width and height is the size of console window
// Name is the window title
void ConsoleListener::Open(bool Hidden, int Width, int Height, const char *Title)
{
#ifdef _WIN32
if (!GetConsoleWindow())
{
// Open the console window and create the window handle for GetStdHandle()
AllocConsole();
// Hide
if (Hidden) ShowWindow(GetConsoleWindow(), SW_HIDE);
// Save the window handle that AllocConsole() created
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// Set the console window title
SetConsoleTitle(UTF8ToTStr(Title).c_str());
// Set letter space
LetterSpace(80, 4000);
//MoveWindow(GetConsoleWindow(), 200,200, 800,800, true);
}
else
{
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
}
#endif
}