[Emulator] Added possiblity to install multiple packages at once

This commit is contained in:
Gliniak 2022-07-30 15:52:41 +02:00
parent 79ffbe3971
commit 5d1b641197
2 changed files with 31 additions and 25 deletions

View File

@ -864,30 +864,29 @@ void EmulatorWindow::FileClose() {
}
void EmulatorWindow::InstallContent() {
std::filesystem::path path;
std::vector<std::filesystem::path> paths;
auto file_picker = xe::ui::FilePicker::Create();
file_picker->set_mode(ui::FilePicker::Mode::kOpen);
file_picker->set_type(ui::FilePicker::Type::kFile);
file_picker->set_multi_selection(false);
file_picker->set_multi_selection(true);
file_picker->set_title("Select Content Package");
file_picker->set_extensions({
{"All Files (*.*)", "*.*"},
});
if (file_picker->Show(window_.get())) {
auto selected_files = file_picker->selected_files();
if (!selected_files.empty()) {
path = selected_files[0];
}
paths = file_picker->selected_files();
}
if (!path.empty()) {
// Normalize the path and make absolute.
auto abs_path = std::filesystem::absolute(path);
auto result = emulator_->InstallContentPackage(abs_path);
if (XFAILED(result)) {
// TODO: Display a message box.
XELOGE("Failed to install content: {:08X}", result);
if (!paths.empty()) {
for (auto path : paths) {
// Normalize the path and make absolute.
auto abs_path = std::filesystem::absolute(path);
auto result = emulator_->InstallContentPackage(abs_path);
if (XFAILED(result)) {
// TODO: Display a message box.
XELOGE("Failed to install content: {:08X}", result);
}
}
}
}

View File

@ -114,7 +114,7 @@ bool Win32FilePicker::Show(Window* parent_window) {
// TODO(benvanik): FileSaveDialog.
assert_true(mode() == Mode::kOpen);
Microsoft::WRL::ComPtr<IFileDialog> file_dialog;
Microsoft::WRL::ComPtr<IFileOpenDialog> file_dialog;
HRESULT hr =
CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&file_dialog));
@ -192,23 +192,30 @@ bool Win32FilePicker::Show(Window* parent_window) {
// Obtain the result once the user clicks the 'Open' button.
// The result is an IShellItem object.
Microsoft::WRL::ComPtr<IShellItem> shell_item;
hr = file_dialog->GetResult(&shell_item);
Microsoft::WRL::ComPtr<IShellItemArray> shell_items;
hr = file_dialog->GetResults(&shell_items);
if (!SUCCEEDED(hr)) {
return false;
}
// We are just going to print out the name of the file for sample sake.
PWSTR file_path = nullptr;
hr = shell_item->GetDisplayName(SIGDN_FILESYSPATH, &file_path);
if (!SUCCEEDED(hr)) {
return false;
}
std::vector<std::filesystem::path> selected_files;
selected_files.push_back(std::filesystem::path(file_path));
set_selected_files(selected_files);
CoTaskMemFree(file_path);
DWORD items_count = 0;
shell_items->GetCount(&items_count);
// Iterate over selected files
for (DWORD i = 0; i < items_count; i++) {
Microsoft::WRL::ComPtr<IShellItem> shell_item;
shell_items->GetItemAt(i, &shell_item);
// We are just going to print out the name of the file for sample sake.
PWSTR file_path = nullptr;
hr = shell_item->GetDisplayName(SIGDN_FILESYSPATH, &file_path);
if (!SUCCEEDED(hr)) {
return false;
}
selected_files.push_back(std::filesystem::path(file_path));
CoTaskMemFree(file_path);
}
set_selected_files(selected_files);
return true;
}