Implemented opening of log folder.

This commit is contained in:
WrinklyNinja
2014-07-12 16:33:45 +01:00
parent fd5264240c
commit f6987290c2
4 changed files with 62 additions and 10 deletions
+29 -3
View File
@@ -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);
}
});
}
+11
View File
@@ -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);
}
+5
View File
@@ -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:
+17 -7
View File
@@ -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;