From 87204c540590feeba783f40319d4a503b9f325f5 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 18 Aug 2014 20:17:45 +0000 Subject: Tox: - added profile manager on first run - reworked options git-svn-id: http://svn.miranda-ng.org/main/trunk@10231 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_utils.cpp | 44 +++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'protocols/Tox/src/tox_utils.cpp') diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index 7c321ac2c7..60dd7e6233 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -125,18 +125,31 @@ std::string CToxProto::DataToHexString(std::vector data) return oss.str(); } -std::string CToxProto::GetToxProfilePath() +bool CToxProto::IsFileExists(std::tstring path) { - std::string profilePath; - ptrA path(getStringA("DataPath")); - if (path) + //return ::GetFileAttributes(fileName) != DWORD(-1) + WIN32_FIND_DATA wfd; + HANDLE hFind = FindFirstFile(path.c_str(), &wfd); + if (INVALID_HANDLE_VALUE != hFind) { - profilePath = path; + FindClose(hFind); + return true; } - if (profilePath.empty()) + return false; +} + +std::tstring CToxProto::GetToxProfilePath() +{ + std::tstring profilePath; + //ptrA path(getStringA("DataPath")); + //if (path) + //{ + // profilePath = path; + //} + //if (profilePath.empty()) { - char defaultPath[MAX_PATH]; - mir_snprintf(defaultPath, MAX_PATH, "%s\\%s.tox", VARS("%miranda_userdata%"), _T2A(m_tszUserName)); + TCHAR defaultPath[MAX_PATH]; + mir_sntprintf(defaultPath, MAX_PATH, _T("%s\\%s.tox"), VARST(_T("%miranda_userdata%")), m_tszUserName); profilePath = defaultPath; } return profilePath; @@ -144,9 +157,8 @@ std::string CToxProto::GetToxProfilePath() int CToxProto::LoadToxData() { - std::string toxProfilePath = GetToxProfilePath(); - FILE *hFile = fopen(toxProfilePath.c_str(), "rb"); - + std::tstring toxProfilePath = GetToxProfilePath(); + FILE *hFile = _wfopen(toxProfilePath.c_str(), _T("rb")); if (hFile) { fseek(hFile, 0, SEEK_END); @@ -182,14 +194,8 @@ int CToxProto::LoadToxData() int CToxProto::SaveToxData() { - ptrA path(getStringA("DataPath")); - if (!path) - { - return 0; - } - - FILE *hFile = fopen(path, "wb"); - + std::tstring toxProfilePath = GetToxProfilePath(); + FILE *hFile = _wfopen(toxProfilePath.c_str(), _T("wb")); if (!hFile) { //perror("[!] load_key"); -- cgit v1.2.3