Skip to content

Commit

Permalink
FrontendService/Dev: Consolidate dialog functions
Browse files Browse the repository at this point in the history
The show_warning, show_error, and show_information functions have been consolidated into show_dialog and now use the pre-existing enum "DialogType" to specify the tone.

Callsites have been updated and some calls have been changed to specify more appropriate titles for the dialogs.
  • Loading branch information
Aurumaker72 committed Dec 10, 2024
1 parent 3bf1627 commit 7bb97fb
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 95 deletions.
2 changes: 1 addition & 1 deletion core/memory/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3700,7 +3700,7 @@ void read_sc_regh()

void read_sc_regd()
{
FrontendService::show_warning(L"read_sc_regd not supported by RCP", L"Error");
FrontendService::show_dialog(L"read_sc_regd not supported by RCP", L"Core", FrontendService::DialogType::Error);
stop = 1;
}

Expand Down
6 changes: 3 additions & 3 deletions core/memory/savestates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,9 @@ namespace Savestates
FrontendService::show_statusbar(std::format(L"Cancelled {}", job == Job::Save ? L"save" : L"load").c_str());
} else
{
FrontendService::show_error(std::format(L"Failed to {} {} (error code {}).\nVerify that the savestate is valid and accessible.",
job == Job::Save ? L"save" : L"load", path.filename().wstring(), (int32_t)result).c_str(),
L"Savestate");
const auto message = std::format(L"Failed to {} {} (error code {}).\nVerify that the savestate is valid and accessible.",
job == Job::Save ? L"save" : L"load", path.filename().wstring(), (int32_t)result);
FrontendService::show_dialog(message.c_str(), L"Savestate", FrontendService::DialogType::Error);
}

if (callback)
Expand Down
2 changes: 1 addition & 1 deletion core/memory/summercart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static char* get_st_path(const char* filename)

static int32_t sd_error(const wchar_t* text, const wchar_t* caption)
{
FrontendService::show_error(text, caption);
FrontendService::show_dialog(text, caption, FrontendService::DialogType::Error);
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions core/r4300/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ void Plugin::config()
auto initiateGFX = (INITIATEGFX)PlatformService::get_function_in_module((void*)m_module, "InitiateGFX");
if (initiateGFX && !initiateGFX(dummy_gfx_info))
{
FrontendService::show_information(L"Couldn't initialize video plugin.");
FrontendService::show_dialog(L"Couldn't initialize video plugin.", L"Core", FrontendService::DialogType::Information);
}
}

Expand All @@ -440,7 +440,7 @@ void Plugin::config()
auto initiateAudio = (INITIATEAUDIO)PlatformService::get_function_in_module((void*)m_module, "InitiateAudio");
if (initiateAudio && !initiateAudio(dummy_audio_info))
{
FrontendService::show_information(L"Couldn't initialize audio plugin.");
FrontendService::show_dialog(L"Couldn't initialize audio plugin.", L"Core", FrontendService::DialogType::Information);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/r4300/cop1_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ double largest_denormal_double = 2.225073858507201e-308; // (1ULL << 52) - 1
void fail_float(const std::wstring& msg)
{
const auto buf = std::format(L"{}\nPC = {:#06x}", msg, interpcore ? interp_addr : PC->addr);
FrontendService::show_error(buf.c_str(), L"Floating Point Error");
FrontendService::show_dialog(buf.c_str(), L"Core", FrontendService::DialogType::Error);

core_Cause = 15 << 2;
exception_general();
Expand Down
28 changes: 14 additions & 14 deletions core/r4300/vcr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ void vcr_create_n_frame_savestate(size_t frame)

if (result != CoreResult::Ok)
{
FrontendService::show_error(std::format(L"Failed to save seek savestate at frame {}.", frame).c_str(), L"VCR");
FrontendService::show_dialog(std::format(L"Failed to save seek savestate at frame {}.", frame).c_str(), L"VCR", FrontendService::DialogType::Error);
return;
}

Expand All @@ -565,7 +565,7 @@ void vcr_handle_starting_tasks(int32_t index, BUTTONS* input)

if (result != CoreResult::Ok)
{
FrontendService::show_error(L"Failed to reset the rom when initiating a from-start recording.\nRecording will be stopped.", L"VCR");
FrontendService::show_dialog(L"Failed to reset the rom when initiating a from-start recording.\nRecording will be stopped.", L"VCR", FrontendService::DialogType::Error);
VCR::stop_all();
return;
}
Expand All @@ -592,7 +592,7 @@ void vcr_handle_starting_tasks(int32_t index, BUTTONS* input)

if (result != CoreResult::Ok)
{
FrontendService::show_error(L"Failed to reset the rom when playing back a from-start movie.\nPlayback will be stopped.", L"VCR");
FrontendService::show_dialog(L"Failed to reset the rom when playing back a from-start movie.\nPlayback will be stopped.", L"VCR", FrontendService::DialogType::Error);
VCR::stop_all();
return;
}
Expand Down Expand Up @@ -667,7 +667,7 @@ void vcr_handle_recording(int32_t index, BUTTONS* input)

if (result != CoreResult::Ok)
{
FrontendService::show_error(L"Failed to reset the rom following a user-invoked reset.");
FrontendService::show_dialog(L"Failed to reset the rom following a user-invoked reset.", L"VCR", FrontendService::DialogType::Error);
}
});
}
Expand Down Expand Up @@ -721,7 +721,7 @@ void vcr_handle_playback(int32_t index, BUTTONS* input)

if (result != CoreResult::Ok)
{
FrontendService::show_error(L"Failed to reset the rom following a movie-invoked reset.\nRecording will be stopped.", L"VCR");
FrontendService::show_dialog(L"Failed to reset the rom following a movie-invoked reset.\nRecording will be stopped.", L"VCR", FrontendService::DialogType::Error);
VCR::stop_all();
g_reset_pending = false;
return;
Expand Down Expand Up @@ -750,7 +750,7 @@ void vcr_stop_seek_if_needed()
if (m_current_sample > seek_to_frame.value())
{
g_core_logger->error("Seek frame exceeded without seek having been stopped. ({}/{})", m_current_sample, seek_to_frame.value());
FrontendService::show_error(L"Seek frame exceeded without seek having been stopped!\nThis incident has been logged, please report this issue along with the log file.", L"VCR");
FrontendService::show_dialog(L"Seek frame exceeded without seek having been stopped!\nThis incident has been logged, please report this issue along with the log file.", L"VCR", FrontendService::DialogType::Error);
}

if (m_current_sample >= seek_to_frame.value())
Expand Down Expand Up @@ -916,7 +916,7 @@ CoreResult VCR::start_record(std::filesystem::path path, uint16_t flags, std::st

if (result != CoreResult::Ok)
{
FrontendService::show_error(L"Failed to save savestate while starting recording.\nRecording will be stopped.", L"VCR");
FrontendService::show_dialog(L"Failed to save savestate while starting recording.\nRecording will be stopped.", L"VCR", FrontendService::DialogType::Error);
VCR::stop_all();
return;
}
Expand Down Expand Up @@ -950,7 +950,7 @@ CoreResult VCR::start_record(std::filesystem::path path, uint16_t flags, std::st

if (result != CoreResult::Ok)
{
FrontendService::show_error(L"Failed to load savestate while starting recording.\nRecording will be stopped.", L"VCR");
FrontendService::show_dialog(L"Failed to load savestate while starting recording.\nRecording will be stopped.", L"VCR", FrontendService::DialogType::Error);
VCR::stop_all();
return;
}
Expand Down Expand Up @@ -1197,7 +1197,7 @@ CoreResult VCR::start_playback(std::filesystem::path path)

if (lstrlenW(dummy) > 0)
{
FrontendService::show_warning(dummy, L"VCR");
FrontendService::show_dialog(dummy, L"VCR", FrontendService::DialogType::Warning);
}

if (g_header.extended_version != 0)
Expand All @@ -1219,7 +1219,7 @@ CoreResult VCR::start_playback(std::filesystem::path path)
// Old movies filled with non-zero data in this section are suspicious, we'll warn the user.
if (g_header.extended_flags.data != 0)
{
FrontendService::show_warning(OLD_MOVIE_EXTENDED_SECTION_NONZERO_MESSAGE, L"VCR");
FrontendService::show_dialog(OLD_MOVIE_EXTENDED_SECTION_NONZERO_MESSAGE, L"VCR", FrontendService::DialogType::Warning);
}
}

Expand Down Expand Up @@ -1285,7 +1285,7 @@ CoreResult VCR::start_playback(std::filesystem::path path)

if (result != CoreResult::Ok)
{
FrontendService::show_error(L"Failed to load savestate while starting playback.\nRecording will be stopped.", L"VCR");
FrontendService::show_dialog(L"Failed to load savestate while starting playback.\nRecording will be stopped.", L"VCR", FrontendService::DialogType::Error);
VCR::stop_all();
return;
}
Expand Down Expand Up @@ -1443,7 +1443,7 @@ CoreResult vcr_begin_seek_impl(std::wstring str, bool pause_at_end, bool resume,
{
if (result != CoreResult::Ok)
{
FrontendService::show_error(L"Failed to load seek savestate for seek operation.", L"VCR");
FrontendService::show_dialog(L"Failed to load seek savestate for seek operation.", L"VCR", FrontendService::DialogType::Error);
g_seek_savestate_loading = false;
VCR::stop_seek();
}
Expand Down Expand Up @@ -1474,7 +1474,7 @@ CoreResult vcr_begin_seek_impl(std::wstring str, bool pause_at_end, bool resume,
if (g_config.seek_savestate_interval == 0)
{
// TODO: We can't backtrack using savestates, so we'd have to restart into recording mode while restoring the buffer, leave it for the next release...
FrontendService::show_error(L"The seek savestate interval can't be 0 when seeking backwards during recording.", L"VCR");
FrontendService::show_dialog(L"The seek savestate interval can't be 0 when seeking backwards during recording.", L"VCR", FrontendService::DialogType::Error);
return CoreResult::VCR_SeekSavestateIntervalZero;
}

Expand Down Expand Up @@ -1511,7 +1511,7 @@ CoreResult vcr_begin_seek_impl(std::wstring str, bool pause_at_end, bool resume,
{
if (result != CoreResult::Ok)
{
FrontendService::show_error(L"Failed to load seek savestate for seek operation.", L"VCR");
FrontendService::show_dialog(L"Failed to load seek savestate for seek operation.", L"VCR", FrontendService::DialogType::Error);
g_seek_savestate_loading = false;
VCR::stop_seek();
}
Expand Down
31 changes: 8 additions & 23 deletions shared/services/FrontendService.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,14 @@ namespace FrontendService
*/
bool show_ask_dialog(const wchar_t* str, const wchar_t* title = nullptr, bool warning = false, void* hwnd = nullptr);

/**
* \brief Shows the user a warning dialog
* \param str The dialog content
* \param title The dialog title
* \param hwnd The parent window
*/
void show_warning(const wchar_t* str, const wchar_t* title = nullptr, void* hwnd = nullptr);

/**
* \brief Shows the user an error dialog
* \param str The dialog content
* \param title The dialog title
* \param hwnd The parent window
*/
void show_error(const wchar_t* str, const wchar_t* title = nullptr, void* hwnd = nullptr);

/**
* \brief Shows the user an information dialog
* \param str The dialog content
* \param title The dialog title
* \param hwnd The parent window
*/
void show_information(const wchar_t* str, const wchar_t* title = nullptr, void* hwnd = nullptr);
/**
* \brief Shows the user a dialog.
* \param str The dialog content.
* \param title The dialog title.
* \param type The dialog tone.
* \param hwnd The parent window.
*/
void show_dialog(const wchar_t* str, const wchar_t* title = nullptr, DialogType type = DialogType::Warning, void* hwnd = nullptr);

/**
* \brief Shows text in the statusbar
Expand Down
2 changes: 1 addition & 1 deletion view/PlatformService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void PlatformService::free_library(void* module)
{
if (!FreeLibrary((HMODULE)module))
{
FrontendService::show_error(std::format(L"Failed to free library {:#06x}.", (unsigned long)module).c_str());
FrontendService::show_dialog(std::format(L"Failed to free library {:#06x}.", (unsigned long)module).c_str(), L"Core", FrontendService::DialogType::Error);
}
}

Expand Down
18 changes: 9 additions & 9 deletions view/capture/EncodingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace EncodingManager
{
if (!MGECompositor::available() && !readScreen)
{
FrontendService::show_error(L"The current video plugin has no readScreen implementation.\nPlugin capture is not possible.", L"Capture");
FrontendService::show_dialog(L"The current video plugin has no readScreen implementation.\nPlugin capture is not possible.", L"Capture", FrontendService::DialogType::Error);
stop_capture();
return;
}
Expand All @@ -225,7 +225,7 @@ namespace EncodingManager
{
if (!MGECompositor::available() && !readScreen)
{
FrontendService::show_error(L"The current video plugin has no readScreen implementation.\nHybrid capture is not possible.", L"Capture");
FrontendService::show_dialog(L"The current video plugin has no readScreen implementation.\nHybrid capture is not possible.", L"Capture", FrontendService::DialogType::Error);
stop_capture();
return;
}
Expand Down Expand Up @@ -312,7 +312,7 @@ namespace EncodingManager

if (!result)
{
FrontendService::show_error(L"Failed to start encoding.\r\nVerify that the encoding parameters are valid and try again.", L"Capture");
FrontendService::show_dialog(L"Failed to start encoding.\r\nVerify that the encoding parameters are valid and try again.", L"Capture", FrontendService::DialogType::Error);
return false;
}

Expand All @@ -337,7 +337,7 @@ namespace EncodingManager

if (!m_encoder->stop())
{
FrontendService::show_error(L"Failed to stop encoding.", L"Capture");
FrontendService::show_dialog(L"Failed to stop encoding.", L"Capture", FrontendService::DialogType::Error);
return false;
}

Expand Down Expand Up @@ -373,9 +373,9 @@ namespace EncodingManager
return;
}

FrontendService::show_error(
FrontendService::show_dialog(
L"Failed to append frame to video.\nPerhaps you ran out of memory?",
L"Capture");
L"Capture", FrontendService::DialogType::Error);
stop_capture();
}

Expand All @@ -399,9 +399,9 @@ namespace EncodingManager

if (!m_encoder->append_audio(reinterpret_cast<uint8_t*>(buf), ai_len, m_audio_bitrate))
{
FrontendService::show_error(
FrontendService::show_dialog(
L"Failed to append audio data.\nCapture will be stopped.",
L"Capture");
L"Capture", FrontendService::DialogType::Error);
stop_capture();
}
}
Expand All @@ -422,7 +422,7 @@ namespace EncodingManager

if (m_capturing)
{
FrontendService::show_error(L"Audio frequency changed during capture.\r\nThe capture will be stopped.", L"Capture");
FrontendService::show_dialog(L"Audio frequency changed during capture.\r\nThe capture will be stopped.", L"Capture", FrontendService::DialogType::Error);
stop_capture();
return;
}
Expand Down
6 changes: 2 additions & 4 deletions view/capture/encoders/AVIEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,7 @@ bool AVIEncoder::write_sound(uint8_t* buf, int len, const int min_write_size, co

if (!ok)
{
FrontendService::show_error(
L"Audio output failure!\nA call to addAudioData() (AVIStreamWrite) failed.\nPerhaps you ran out of memory?",
nullptr);
FrontendService::show_dialog(L"Audio output failure!\nA call to addAudioData() (AVIStreamWrite) failed.\nPerhaps you ran out of memory?", L"AVI Encoder", FrontendService::DialogType::Error);
return false;
}
}
Expand All @@ -289,7 +287,7 @@ bool AVIEncoder::write_sound(uint8_t* buf, int len, const int min_write_size, co

if (static_cast<unsigned int>(sound_buf_pos + len) > SOUND_BUF_SIZE * sizeof(char))
{
FrontendService::show_error(L"Sound buffer overflow!\nCapture will be stopped.", L"AVI Encoder");
FrontendService::show_dialog(L"Sound buffer overflow!\nCapture will be stopped.", L"AVI Encoder", FrontendService::DialogType::Error);
return false;
}

Expand Down
7 changes: 4 additions & 3 deletions view/capture/encoders/FFmpegEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ bool FFmpegEncoder::start(Params params)
&m_pi)
)
{
FrontendService::show_error(std::format(L"Could not start ffmpeg process! Does ffmpeg exist on disk at '{}'?", g_config.ffmpeg_path).c_str());

FrontendService::show_dialog(std::format(L"Could not start ffmpeg process! Does ffmpeg exist on disk at '{}'?", g_config.ffmpeg_path).c_str(), L"FFmpeg Encoder", FrontendService::DialogType::Error);
g_view_logger->info(L"CreateProcess failed ({}).", GetLastError());
CloseHandle(m_video_pipe);
CloseHandle(m_audio_pipe);
Expand Down Expand Up @@ -113,12 +114,12 @@ bool FFmpegEncoder::stop()

if (!this->m_video_queue.empty() || !this->m_audio_queue.empty())
{
FrontendService::show_warning(std::format(L"Capture stopped with {} video, {} audio elements remaining in queue!\nThe capture might be corrupted.", this->m_video_queue.size(), this->m_audio_queue.size()).c_str());
FrontendService::show_dialog(std::format(L"Capture stopped with {} video, {} audio elements remaining in queue!\nThe capture might be corrupted.", this->m_video_queue.size(), this->m_audio_queue.size()).c_str(), L"FFmpeg");
}

if (m_dropped_frames > 0)
{
FrontendService::show_warning(std::format(L"{} frames were dropped during capture to avoid out-of-memory errors.\nThe capture might contain empty frames.", m_dropped_frames).c_str());
FrontendService::show_dialog(std::format(L"{} frames were dropped during capture to avoid out-of-memory errors.\nThe capture might contain empty frames.", m_dropped_frames).c_str(), L"FFmpeg");
}

free(m_silence_buffer);
Expand Down
Loading

0 comments on commit 7bb97fb

Please sign in to comment.