Skip to content

Commit

Permalink
Fix some UTF8 strings (#570)
Browse files Browse the repository at this point in the history
Closes #562, closes #564
  • Loading branch information
vktr committed Apr 13, 2018
1 parent 68e2ebd commit ff2650f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/picotorrent/applicationupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ ApplicationUpdater::~ApplicationUpdater()

void ApplicationUpdater::Check(bool force)
{
std::string updateUrl = m_config->UpdateUrl();
wxString updateUrl = m_config->UpdateUrl();

m_httpClient->GetAsync(
Utils::ToWideString(updateUrl.c_str(), static_cast<int>(updateUrl.size())),
updateUrl.ToStdWstring(),
std::bind(&ApplicationUpdater::OnHttpResponse, this, std::placeholders::_1, force));
}

Expand Down
12 changes: 6 additions & 6 deletions src/picotorrent/errorhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ bool ErrorHandler::Report(const wchar_t* path, const wchar_t* id, void* context,
std::map<std::wstring, std::wstring> params;
std::map<std::wstring, std::wstring> files;

std::string branch = BuildInfo::Branch();
std::string commitish = BuildInfo::Commitish();
std::string version = BuildInfo::Version();
wxString branch = BuildInfo::Branch();
wxString commitish = BuildInfo::Commitish();
wxString version = BuildInfo::Version();

params.insert({ L"branch", Utils::ToWideString(branch.c_str(), branch.size()) });
params.insert({ L"commitish", Utils::ToWideString(commitish.c_str(), commitish.size()) });
params.insert({ L"version", Utils::ToWideString(version.c_str(), version.size()) });
params.insert({ L"branch", branch.ToStdWstring() });
params.insert({ L"commitish", commitish.ToStdWstring() });
params.insert({ L"version", version.ToStdWstring() });

fs::path dmpFile = fs::path(path) / fs::path(id).replace_extension(".dmp");
files.insert({ L"minidump", dmpFile.wstring() });
Expand Down
5 changes: 4 additions & 1 deletion src/picotorrent/filestorageviewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ void FileStorageViewModel::GetValue(wxVariant &variant, const wxDataViewItem &it
icon = GetIconForFile(node->name);
}

variant << wxDataViewIconText(node->name, icon);
variant << wxDataViewIconText(
wxString::FromUTF8(node->name),
icon);

break;
}
case Columns::Size:
Expand Down
2 changes: 1 addition & 1 deletion src/picotorrent/torrentlistviewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void TorrentListViewModel::GetValueByRow(wxVariant &variant, unsigned int row, u
}
else
{
variant = ts.name;
variant = wxString::FromUTF8(ts.name);
}
break;
case Columns::QueuePosition:
Expand Down
7 changes: 2 additions & 5 deletions src/picotorrent/translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "config.hpp"
#include "environment.hpp"
#include "picojson.hpp"
#include "utils.hpp"

namespace fs = std::experimental::filesystem::v1;
namespace pj = picojson;
Expand Down Expand Up @@ -124,14 +123,12 @@ bool Translator::LoadLanguageFromJson(std::string const& json, Translator::Langu

Language l;
l.code = langId;
l.name = Utils::ToWideString(langName.c_str(), static_cast<int>(langName.size()));
l.name = wxString::FromUTF8(langName);

for (auto& p : obj.at("strings").get<pj::object>())
{
std::string val = p.second.get<std::string>();
wxString converted = Utils::ToWideString(val.c_str(), static_cast<int>(val.size()));

l.translations.insert({ p.first, converted });
l.translations.insert({ p.first, wxString::FromUTF8(val) });
}

lang = l;
Expand Down
8 changes: 0 additions & 8 deletions src/picotorrent/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,3 @@ wxString Utils::ToReadableStatus(lt::torrent_status const& ts, std::shared_ptr<p

return i18n(tr, "unknown");
}

std::wstring Utils::ToWideString(const char* buffer, int bufferSize)
{
int size = MultiByteToWideChar(CP_UTF8, 0, buffer, bufferSize, NULL, 0);
std::wstring result(size, '\0');
MultiByteToWideChar(CP_UTF8, 0, buffer, bufferSize, &result[0], size);
return result;
}
1 change: 0 additions & 1 deletion src/picotorrent/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ namespace pt
static void OpenAndSelect(std::experimental::filesystem::v1::path path);
static wxString ToHumanFileSize(int64_t bytes);
static wxString ToReadableStatus(libtorrent::torrent_status const& ts, std::shared_ptr<Translator> translator);
static std::wstring ToWideString(const char* buffer, int bufferSize);
};
}

0 comments on commit ff2650f

Please sign in to comment.