From f6987290c2087a1f16a3262b8d1bf1ff668ac024 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Sun, 8 Jun 2014 20:08:04 +0100 Subject: [PATCH] Implemented opening of log folder. --- resources/report/js/script.js | 32 +++++++++++++++++++++++++++++--- src/backend/helpers.cpp | 11 +++++++++++ src/backend/helpers.h | 5 +++++ src/gui/handler.cpp | 24 +++++++++++++++++------- 4 files changed, 62 insertions(+), 10 deletions(-) diff --git a/resources/report/js/script.js b/resources/report/js/script.js index 3d2c1517..6c32cfcc 100644 --- a/resources/report/js/script.js +++ b/resources/report/js/script.js @@ -186,20 +186,46 @@ function showMessageDialog(title, text) { clone.getElementsByClassName('cancel')[0].addEventListener('click', hideDialog, false); } function showMessageBox(type, title, text) { + var content = document.getElementById('messageDialog').content; + var clone = document.importNode(content, true); + document.body.appendChild(clone); + clone = document.body.lastElementChild; + clone.id = 'modalDialog'; + + clone.getElementsByTagName('span')[0].classList.add(type); + + clone.getElementsByTagName('h1')[0].textContent = title; + clone.getElementsByTagName('p')[0].textContent = text; + + var overlay = document.getElementById('overlay'); + overlay.removeEventListener('click', hideDialog, false); + showElement(overlay); + + clone.getElementsByClassName('accept')[0].textContent = 'OK'; + clone.getElementsByClassName('accept')[0].setAttribute('data-dialog', clone.id); + clone.getElementsByClassName('accept')[0].addEventListener('click', hideDialog, false); + + hideElement(clone.getElementsByClassName('cancel')[0]); } function openLogLocation(evt) { - + var request_id = window.cefQuery({ + request: 'openLogLocation', + persistent: false, + onSuccess: function(response) {}, + onFailure: function(error_code, error_message) { + showMessageBox('error', "Error", "Error code: " + error_code + "; " + error_message); + } + }); } function openReadme(evt) { - // Create and send a new query. var request_id = window.cefQuery({ request: 'openReadme', persistent: false, onSuccess: function(response) {}, onFailure: function(error_code, error_message) { - alert(error_code + error_message); + showMessageBox('error', "Error", "Error code: " + error_code + "; " + error_message); } }); } diff --git a/src/backend/helpers.cpp b/src/backend/helpers.cpp index 99c551f4..04367d7a 100644 --- a/src/backend/helpers.cpp +++ b/src/backend/helpers.cpp @@ -221,6 +221,17 @@ namespace loot { return "file:///" + file.string(); //Seems that we don't need to worry about encoding, tested with Unicode paths. } +#if _WIN32 || _WIN64 + //Helper to turn UTF8 strings into strings that can be used by WinAPI. + std::wstring ToWinWide(const std::string& str) { + + int len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length() + 1, 0, 0); + std::wstring wstr(len, NULL); + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length() + 1, &(wstr[0]), len); + return wstr; + } +#endif + Language::Language(const unsigned int code) { Construct(code); } diff --git a/src/backend/helpers.h b/src/backend/helpers.h index 6ed628c5..9d3d786e 100644 --- a/src/backend/helpers.h +++ b/src/backend/helpers.h @@ -60,6 +60,11 @@ namespace loot { //Turns an absolute filesystem path into a valid file:// URL. std::string ToFileURL(const boost::filesystem::path& file); +#if _WIN32 || _WIN64 + //Helper to turn UTF8 strings into strings that can be used by WinAPI. + std::wstring ToWinWide(const std::string& str); +#endif + //Language class for simpler language support. class Language { public: diff --git a/src/gui/handler.cpp b/src/gui/handler.cpp index 76c7fba2..b8c0902b 100644 --- a/src/gui/handler.cpp +++ b/src/gui/handler.cpp @@ -55,13 +55,23 @@ namespace loot { const std::string& message_name = request; if (message_name.find("openReadme") == 0) { // Open readme in default application. - std::string url = ToFileURL(g_path_readme); - int len = MultiByteToWideChar(CP_UTF8, 0, url.c_str(), url.length() + 1, 0, 0); - std::wstring wurl(len, NULL); - MultiByteToWideChar(CP_UTF8, 0, url.c_str(), url.length() + 1, &(wurl[0]), len); - ShellExecute(0, NULL, wurl.c_str(), NULL, NULL, SW_SHOWNORMAL); - callback->Success(request); - return true; + HINSTANCE ret = ShellExecute(0, NULL, ToWinWide(ToFileURL(g_path_readme)).c_str(), NULL, NULL, SW_SHOWNORMAL); + if ((int)ret > 32) { + callback->Success(request); + return true; + } + else + callback->Failure((int)ret, "Shell execute failed."); + } + else if (message_name == "openLogLocation") { + //Open debug log folder. + HINSTANCE ret = ShellExecute(NULL, L"open", ToWinWide(g_path_log.parent_path().string()).c_str(), NULL, NULL, SW_SHOWNORMAL); + if ((int)ret > 32) { + callback->Success(request); + return true; + } + else + callback->Failure((int)ret, "Shell execute failed."); } return false;