Compare commits

...

2 Commits

Author SHA1 Message Date
Stenzek d8bf0c81a7
Updater: Use IFileOperation 2024-04-05 19:26:12 +10:00
Stenzek 26c76d184f
Qt: Fix toolbar position not saving 2024-04-05 19:21:56 +10:00
3 changed files with 111 additions and 28 deletions

View File

@ -162,7 +162,7 @@ void MainWindow::initialize()
setupAdditionalUi();
connectSignals();
restoreGeometryFromConfig();
restoreStateFromConfig();
switchToGameListView();
updateWindowTitle();
@ -2462,29 +2462,76 @@ void MainWindow::onSettingsResetToDefault(bool system, bool controller)
updateMenuSelectedTheme();
}
void MainWindow::saveGeometryToConfig()
void MainWindow::saveStateToConfig()
{
const QByteArray geometry = saveGeometry();
const QByteArray geometry_b64 = geometry.toBase64();
const std::string old_geometry_b64 = Host::GetBaseStringSettingValue("UI", "MainWindowGeometry");
if (!isVisible() || ((windowState() & Qt::WindowFullScreen) != Qt::WindowNoState))
return;
bool changed = false;
const QByteArray geometry(saveGeometry());
const QByteArray geometry_b64(geometry.toBase64());
const std::string old_geometry_b64(Host::GetBaseStringSettingValue("UI", "MainWindowGeometry"));
if (old_geometry_b64 != geometry_b64.constData())
{
Host::SetBaseStringSettingValue("UI", "MainWindowGeometry", geometry_b64.constData());
Host::CommitBaseSettingChanges();
changed = true;
}
const QByteArray state(saveState());
const QByteArray state_b64(state.toBase64());
const std::string old_state_b64(Host::GetBaseStringSettingValue("UI", "MainWindowState"));
if (old_state_b64 != state_b64.constData())
{
Host::SetBaseStringSettingValue("UI", "MainWindowState", state_b64.constData());
changed = true;
}
if (changed)
Host::CommitBaseSettingChanges();
}
void MainWindow::restoreGeometryFromConfig()
void MainWindow::restoreStateFromConfig()
{
const std::string geometry_b64 = Host::GetBaseStringSettingValue("UI", "MainWindowGeometry");
const QByteArray geometry = QByteArray::fromBase64(QByteArray::fromStdString(geometry_b64));
if (!geometry.isEmpty())
restoreGeometry(geometry);
{
const std::string geometry_b64 = Host::GetBaseStringSettingValue("UI", "MainWindowGeometry");
const QByteArray geometry = QByteArray::fromBase64(QByteArray::fromStdString(geometry_b64));
if (!geometry.isEmpty())
restoreGeometry(geometry);
}
{
const std::string state_b64 = Host::GetBaseStringSettingValue("UI", "MainWindowState");
const QByteArray state = QByteArray::fromBase64(QByteArray::fromStdString(state_b64));
if (!state.isEmpty())
{
restoreState(state);
// make sure we're not loading a dodgy config which had fullscreen set...
setWindowState(windowState() & ~(Qt::WindowFullScreen | Qt::WindowActive));
}
{
QSignalBlocker sb(m_ui.actionViewToolbar);
m_ui.actionViewToolbar->setChecked(!m_ui.toolBar->isHidden());
}
{
QSignalBlocker sb(m_ui.actionViewStatusBar);
m_ui.actionViewStatusBar->setChecked(!m_ui.statusBar->isHidden());
}
}
}
void MainWindow::saveDisplayWindowGeometryToConfig()
{
const QByteArray geometry = getDisplayContainer()->saveGeometry();
QWidget* container = getDisplayContainer();
if (container->windowState() & Qt::WindowFullScreen)
{
// if we somehow ended up here, don't save the fullscreen state to the config
return;
}
const QByteArray geometry = container->saveGeometry();
const QByteArray geometry_b64 = geometry.toBase64();
const std::string old_geometry_b64 = Host::GetBaseStringSettingValue("UI", "DisplayWindowGeometry");
if (old_geometry_b64 != geometry_b64.constData())
@ -2500,9 +2547,17 @@ void MainWindow::restoreDisplayWindowGeometryFromConfig()
const QByteArray geometry = QByteArray::fromBase64(QByteArray::fromStdString(geometry_b64));
QWidget* container = getDisplayContainer();
if (!geometry.isEmpty())
{
container->restoreGeometry(geometry);
// make sure we're not loading a dodgy config which had fullscreen set...
container->setWindowState(container->windowState() & ~(Qt::WindowFullScreen | Qt::WindowActive));
}
else
{
// default size
container->resize(640, 480);
}
}
SettingsWindow* MainWindow::getSettingsDialog()
@ -2640,7 +2695,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
// If there's no VM, we can just exit as normal.
if (!s_system_valid || !m_display_created)
{
saveGeometryToConfig();
saveStateToConfig();
if (m_display_created)
g_emu_thread->stopFullscreenUI();
destroySubWindows();
@ -2657,7 +2712,7 @@ void MainWindow::closeEvent(QCloseEvent* event)
return;
// Application will be exited in VM stopped handler.
saveGeometryToConfig();
saveStateToConfig();
m_is_closing = true;
}

View File

@ -224,8 +224,8 @@ private:
void switchToGameListView();
void switchToEmulationView();
void saveGeometryToConfig();
void restoreGeometryFromConfig();
void saveStateToConfig();
void restoreStateFromConfig();
void saveDisplayWindowGeometryToConfig();
void restoreDisplayWindowGeometryFromConfig();
void createDisplayWidget(bool fullscreen, bool render_to_main, bool use_main_window_pos);

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#include "updater.h"
@ -21,7 +21,9 @@
#ifdef _WIN32
#include "common/windows_headers.h"
#include <Shobjidl.h>
#include <shellapi.h>
#include <wrl/client.h>
#else
#include <sys/stat.h>
#endif
@ -87,16 +89,43 @@ bool Updater::RecursiveDeleteDirectory(const char* path, bool remove_dir)
if (!remove_dir)
return false;
// making this safer on Win32...
std::wstring wpath(StringUtil::UTF8StringToWideString(path));
wpath += L'\0';
Microsoft::WRL::ComPtr<IFileOperation> fo;
HRESULT hr = CoCreateInstance(CLSID_FileOperation, NULL, CLSCTX_ALL, IID_PPV_ARGS(fo.ReleaseAndGetAddressOf()));
if (FAILED(hr))
{
m_progress->DisplayFormattedError("CoCreateInstance() for IFileOperation failed: %08X", hr);
return false;
}
SHFILEOPSTRUCTW op = {};
op.wFunc = FO_DELETE;
op.pFrom = wpath.c_str();
op.fFlags = FOF_NOCONFIRMATION;
Microsoft::WRL::ComPtr<IShellItem> item;
hr = SHCreateItemFromParsingName(StringUtil::UTF8StringToWideString(path).c_str(), NULL,
IID_PPV_ARGS(item.ReleaseAndGetAddressOf()));
if (FAILED(hr))
{
m_progress->DisplayFormattedError("SHCreateItemFromParsingName() for delete failed: %08X", hr);
return false;
}
return (SHFileOperationW(&op) == 0 && !op.fAnyOperationsAborted);
hr = fo->SetOperationFlags(FOF_NOCONFIRMATION | FOF_SILENT);
if (FAILED(hr))
m_progress->DisplayFormattedWarning("IFileOperation::SetOperationFlags() failed: %08X", hr);
hr = fo->DeleteItem(item.Get(), nullptr);
if (FAILED(hr))
{
m_progress->DisplayFormattedError("IFileOperation::DeleteItem() failed: %08X", hr);
return false;
}
item.Reset();
hr = fo->PerformOperations();
if (FAILED(hr))
{
m_progress->DisplayFormattedError("IFileOperation::PerformOperations() failed: %08X", hr);
return false;
}
return true;
#else
FileSystem::FindResultsArray results;
if (FileSystem::FindFiles(path, "*", FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_FOLDERS | FILESYSTEM_FIND_HIDDEN_FILES,
@ -382,9 +411,8 @@ bool Updater::CommitUpdate()
Error error;
#ifdef _WIN32
const bool result =
MoveFileExW(StringUtil::UTF8StringToWideString(staging_file_name).c_str(),
StringUtil::UTF8StringToWideString(dest_file_name).c_str(), MOVEFILE_REPLACE_EXISTING);
const bool result = MoveFileExW(FileSystem::GetWin32Path(staging_file_name).c_str(),
FileSystem::GetWin32Path(dest_file_name).c_str(), MOVEFILE_REPLACE_EXISTING);
if (!result)
error.SetWin32(GetLastError());
#elif defined(__APPLE__)