rMsgBox eliminated

This commit is contained in:
Nekotekina 2015-12-19 14:40:52 +03:00
parent a666318b95
commit 4b7f9c38a6
12 changed files with 70 additions and 139 deletions

View file

@ -1,11 +1,13 @@
#include "stdafx.h"
#include "rPlatform.h"
#include "Log.h"
#include "rMsgBox.h"
#include <iostream>
#include <cinttypes>
#include "Thread.h"
#include "File.h"
#include "Log.h"
#ifdef _WIN32
#include <Windows.h>
#endif
using namespace Log;
@ -93,13 +95,17 @@ struct FileListener : LogListener
fs::file mFile;
bool mPrependChannelName;
FileListener(const std::string& name = _PRGNAME_, bool prependChannel = true)
: mFile(fs::get_config_dir() + name + ".log", fom::rewrite)
FileListener(const std::string& name = _PRGNAME_ ".log", bool prependChannel = true)
: mFile(fs::get_config_dir() + name, fom::rewrite)
, mPrependChannelName(prependChannel)
{
if (!mFile)
{
rMessageBox("Can't create log file! (" + name + ".log)", "Error", rICON_ERROR);
#ifdef _WIN32
MessageBoxA(0, ("Can't create log file: " + name).c_str(), "Error", MB_ICONERROR);
#else
std::printf("Can't create log file: %s\n", name.c_str());
#endif
}
}
@ -137,7 +143,7 @@ LogManager::LogManager()
it->addListener(listener);
it++;
}
std::shared_ptr<LogListener> TTYListener(new FileListener("TTY",false));
std::shared_ptr<LogListener> TTYListener(new FileListener("TTY.log", false));
getChannel(TTY).addListener(TTYListener);
#ifdef BUFFERED_LOGGING
mLogConsumer = std::thread(&LogManager::consumeLog, this);
@ -257,20 +263,23 @@ void log_message(Log::LogType type, Log::Severity sev, std::string text)
{
if (g_log_manager)
{
// another msvc bug makes this not work, uncomment this when it's fixed
//g_log_manager->log({logType, severity, text});
Log::LogMessage msg{ type, sev, std::move(text) };
g_log_manager->log(msg);
g_log_manager->log({ type, sev, std::move(text) });
}
else
{
rMessageBox(text,
const auto severity =
sev == Severity::Notice ? "Notice" :
sev == Severity::Warning ? "Warning" :
sev == Severity::Success ? "Success" :
sev == Severity::Error ? "Error" : "Unknown",
sev == Severity::Notice ? rICON_INFORMATION :
sev == Severity::Warning ? rICON_EXCLAMATION :
sev == Severity::Error ? rICON_ERROR : rICON_INFORMATION);
sev == Severity::Error ? "Error" : "Unknown";
#ifdef _WIN32
MessageBoxA(0, text.c_str(), severity,
sev == Severity::Notice ? MB_ICONINFORMATION :
sev == Severity::Warning ? MB_ICONEXCLAMATION :
sev == Severity::Error ? MB_ICONERROR : MB_ICONINFORMATION);
#else
std::printf("[Log:%s] %s\n", severity, text.c_str());
#endif
}
}

View file

@ -1,38 +0,0 @@
#include "stdafx.h"
#include "restore_new.h"
#pragma warning(push)
#pragma message("TODO: remove wx dependency: <wx/msgdlg.h>")
#pragma warning(disable : 4996)
#include <wx/msgdlg.h>
#pragma warning(pop)
#include "define_new_memleakdetect.h"
#include "rMsgBox.h"
#ifndef QT_UI
rMessageDialog::rMessageDialog(void *parent, const std::string& msg, const std::string& title , long style )
{
handle = reinterpret_cast<void*>(new wxMessageDialog(
reinterpret_cast<wxWindow*>(parent)
, fmt::FromUTF8(msg)
, fmt::FromUTF8(title)
, style
));
}
rMessageDialog::~rMessageDialog()
{
delete reinterpret_cast<wxMessageDialog*>(handle);
}
long rMessageDialog::ShowModal()
{
return reinterpret_cast<wxMessageDialog*>(handle)->ShowModal();
}
long rMessageBox(const std::string& message, const std::string& title, long style)
{
return wxMessageBox(fmt::FromUTF8(message), fmt::FromUTF8(title),style);
}
#endif

View file

@ -1,38 +0,0 @@
#pragma once
enum MsgBoxParams : unsigned long
{
rYES_DEFAULT = 0x0,
rOK_DEFAULT = 0x0,
rCENTRE = 0x1,
rYES = 0x2, //res
rOK = 0x4,
rNO = 0x8, //res
rCANCEL = 0x10,
rYES_NO = 0xA,
rNO_DEFAULT = 0x80,
rICON_EXCLAMATION = 0x100,
rICON_ERROR = 0x200,
rICON_HAND = 0x200,
rICON_QUESTION = 0x400,
rICON_INFORMATION = 0x800,
rHELP = 0x1000,
rID_CANCEL = 0x13ED,
rID_YES = 0x13EF, //resDialog
rSTAY_ON_TOP = 0x8000,
rICON_NONE = 0x40000,
rICON_AUTH_NEEDED = 0x80000,
rCANCEL_DEFAULT = 0x80000000,
};
struct rMessageDialog
{
rMessageDialog(void *parent, const std::string& msg, const std::string& title = "RPCS3", long style = rOK | rCENTRE);
rMessageDialog(const rMessageDialog& other) = delete;
~rMessageDialog();
long ShowModal();
void *handle;
};
long rMessageBox(const std::string& message, const std::string& title,long style);