89 lines
3.3 KiB
C++
89 lines
3.3 KiB
C++
#include "pch.h"
|
|
#include "App.xaml.h"
|
|
#include "MainWindow.xaml.h"
|
|
#include "VavCore/VavCore.h"
|
|
#include "src/Logger/SimpleLogger.h"
|
|
#include "src/Logger/LogManager.h"
|
|
#include "src/Utils/DecoderTypeUtils.h"
|
|
#include <sstream>
|
|
|
|
using namespace winrt;
|
|
using namespace winrt::Microsoft::UI::Xaml;
|
|
|
|
namespace winrt::Vav2Player::implementation
|
|
{
|
|
App::App()
|
|
{
|
|
InitializeComponent();
|
|
|
|
// Initialize VavCore on startup
|
|
VavCoreResult result = vavcore_initialize();
|
|
if (result == VAVCORE_SUCCESS)
|
|
{
|
|
const char* version = vavcore_get_version_string();
|
|
::Vav2Player::SimpleLogger::GetInstance().LogInfoF("[App] VavCore initialized successfully, version: %s", version);
|
|
}
|
|
else
|
|
{
|
|
::Vav2Player::SimpleLogger::GetInstance().LogErrorF("[App] Failed to initialize VavCore: error code %d", result);
|
|
}
|
|
|
|
#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
|
|
UnhandledException([](IInspectable const&, UnhandledExceptionEventArgs const& e)
|
|
{
|
|
if (IsDebuggerPresent())
|
|
{
|
|
auto errorMessage = e.Message();
|
|
__debugbreak();
|
|
}
|
|
});
|
|
#endif
|
|
}
|
|
|
|
App::~App()
|
|
{
|
|
// Detach all log outputs before shutdown to prevent crashes
|
|
// when UI components (like LogMessagePage) are being destroyed
|
|
::Vav2Player::LogManager::GetInstance().DetachAllLogOutputs();
|
|
|
|
// Cleanup VavCore
|
|
vavcore_cleanup();
|
|
}
|
|
|
|
void App::OnLaunched(LaunchActivatedEventArgs const&)
|
|
{
|
|
// Log current decoder settings on app launch
|
|
try {
|
|
auto localSettings = winrt::Windows::Storage::ApplicationData::Current().LocalSettings();
|
|
auto values = localSettings.Values();
|
|
|
|
if (values.HasKey(L"DecoderType")) {
|
|
int32_t decoderTypeInt = winrt::unbox_value<int32_t>(values.Lookup(L"DecoderType"));
|
|
|
|
const char* decoderName = ::Vav2Player::Utils::GetDecoderTypeName(
|
|
static_cast<VavCoreDecoderType>(decoderTypeInt));
|
|
|
|
// Log to UI (LogManager)
|
|
std::wstring decoderTypeName(decoderName, decoderName + strlen(decoderName));
|
|
std::wostringstream logMsg;
|
|
logMsg << L"Current decoder setting: " << decoderTypeName
|
|
<< L" (type=" << decoderTypeInt << L")";
|
|
::Vav2Player::LogManager::GetInstance().LogInfo(logMsg.str(), L"App");
|
|
|
|
::Vav2Player::SimpleLogger::GetInstance().LogInfoF(
|
|
"[App] Current decoder setting: %s (type=%d)", decoderName, decoderTypeInt);
|
|
} else {
|
|
::Vav2Player::LogManager::GetInstance().LogInfo(L"No decoder setting found, will use AUTO", L"App");
|
|
::Vav2Player::SimpleLogger::GetInstance().LogInfo(
|
|
"[App] No decoder setting found, will use AUTO");
|
|
}
|
|
} catch (...) {
|
|
::Vav2Player::LogManager::GetInstance().LogError(L"Failed to read decoder settings", L"App");
|
|
::Vav2Player::SimpleLogger::GetInstance().LogError(
|
|
"[App] Failed to read decoder settings");
|
|
}
|
|
|
|
window = winrt::make<implementation::MainWindow>();
|
|
window.Activate();
|
|
}
|
|
} |