diff --git a/Source/GUI/Qt/prefs.cpp b/Source/GUI/Qt/prefs.cpp index acd0fd4d7..2f34fb844 100644 --- a/Source/GUI/Qt/prefs.cpp +++ b/Source/GUI/Qt/prefs.cpp @@ -47,6 +47,7 @@ Preferences::Preferences(QSettings* settings, Core* C, QWidget *parent) : ui->closeAllBeforeOpen->setChecked(settings->value("closeBeforeOpen",true).toBool()); ui->comboBox_defaultview->setCurrentIndex(settings->value("defaultView",VIEW_EASY).toInt()); ui->shellExtension->setChecked(settings->value("shellExtension",true).toBool()); + ui->shellExtension_separateInstance->setChecked(settings->value("shellExtension_separateInstance",false).toBool()); ui->informVersion->setChecked(settings->value("informVersion",false).toBool()); ui->informTimestamp->setChecked(settings->value("informTimestamp",false).toBool()); ui->displayCaptions->setCurrentIndex(settings->value("displayCaptions",1).toInt()); @@ -60,6 +61,12 @@ Preferences::Preferences(QSettings* settings, Core* C, QWidget *parent) : ui->checkForNewVersion->setVisible(false); #endif +#ifndef _WIN32 // Shell extension not yet implemented for non-Windows + ui->shellExtension->setVisible(false); + ui->shellExtension_separateInstance->setVisible(false); +#endif + ui->shellInfoTip->setVisible(false); // InfoTip not yet implemented + #if defined(_WIN32) && defined(WINAPI_FAMILY) && (WINAPI_FAMILY==WINAPI_FAMILY_APP) //Setup UI for winRT ui->rememberToolBarPosition->setVisible(false); ui->rememberGeometry->setVisible(false); @@ -115,6 +122,7 @@ void Preferences::saveSettings() { settings->setValue("rememberToolBarPosition",ui->rememberToolBarPosition->isChecked()); settings->setValue("rememberGeometry",ui->rememberGeometry->isChecked()); settings->setValue("shellExtension",ui->shellExtension->isChecked()); + settings->setValue("shellExtension_separateInstance",ui->shellExtension_separateInstance->isChecked()); settings->setValue("informVersion",ui->informVersion->isChecked()); settings->setValue("informTimestamp",ui->informTimestamp->isChecked()); settings->setValue("displayCaptions",ui->displayCaptions->currentIndex()); diff --git a/Source/GUI/Qt/prefs.ui b/Source/GUI/Qt/prefs.ui index c22c987ce..3fcd9d1b4 100644 --- a/Source/GUI/Qt/prefs.ui +++ b/Source/GUI/Qt/prefs.ui @@ -120,32 +120,50 @@ QLayout::SizeConstraint::SetFixedSize - - - - Default View + + + + + 0 + 0 + + + + 25 + + + + + Open each item in a separate instance + + + + + + Shell InfoTip - - - - Qt::Orientation::Vertical + + + + Shell extension - - - 20 - 40 - + + + + + + Default View - + @@ -154,22 +172,18 @@ - - - - Shell extension + + + + Qt::Orientation::Vertical - - - - - - - 0 - 0 - + + + 20 + 40 + - + diff --git a/Source/GUI/VCL/GUI_Preferences.cpp b/Source/GUI/VCL/GUI_Preferences.cpp index a2c2cdbca..a44898258 100644 --- a/Source/GUI/VCL/GUI_Preferences.cpp +++ b/Source/GUI/VCL/GUI_Preferences.cpp @@ -343,6 +343,18 @@ void __fastcall TPreferencesF::Language_EditClick(TObject *Sender) void __fastcall TPreferencesF::OKClick(TObject *Sender) { Prefs->Config.Save(); + if (CB_InscrireShell_SeparateInstance->Visible) { + TRegistry* Reg = new TRegistry(KEY_WRITE); + try { + if (Reg->OpenKey(__T("Software\\MediaArea\\MediaInfo"), true)) { + if (CB_InscrireShell_SeparateInstance->Checked) + Reg->WriteInteger("ShellExtension_SeparateInstance", 1); + else + Reg->DeleteValue("ShellExtension_SeparateInstance"); + } + } catch (...) {} + delete Reg; + } } //--------------------------------------------------------------------------- @@ -691,6 +703,25 @@ void __fastcall TPreferencesF::GUI_Configure() Tree->FullExpand(); Page->ActivePage=Setup; + //Enable separate instance option if modern shell extension is installed + TRegistry* Reg = new TRegistry; + try { + Reg->RootKey = HKEY_CLASSES_ROOT; + if (Reg->OpenKeyReadOnly(__T("PackagedCom\\ClassIndex\\{20669675-B281-4C4F-94FB-CB6FD3995545}"))) { + CB_InscrireShell_SeparateInstance->Visible=true; + Reg->RootKey = HKEY_CURRENT_USER; + if (Reg->OpenKeyReadOnly(__T("Software\\MediaArea\\MediaInfo"))) { + if (Reg->ValueExists("ShellExtension_SeparateInstance")) + CB_InscrireShell_SeparateInstance->Checked=Reg->ReadInteger("ShellExtension_SeparateInstance"); + } + } + } catch (...) {} + delete Reg; + + //Move InfoTip option up to prevent blank space if there is a space + if (!CB_InscrireShell_SeparateInstance->Visible) + CB_InfoTip->Top=CB_InscrireShell_Folder->Top+CB_InscrireShell_Folder->Height*0.9; + //Translation //Title Caption=Prefs->Translate(__T("Preferences")).c_str(); diff --git a/Source/GUI/VCL/GUI_Preferences.dfm b/Source/GUI/VCL/GUI_Preferences.dfm index 7312fc1bf..457ec29f9 100644 --- a/Source/GUI/VCL/GUI_Preferences.dfm +++ b/Source/GUI/VCL/GUI_Preferences.dfm @@ -145,7 +145,7 @@ object PreferencesF: TPreferencesF end object CB_InfoTip: TCheckBox Left = 2 - Top = 104 + Top = 120 Width = 655 Height = 18 Caption = @@ -176,6 +176,16 @@ object PreferencesF: TPreferencesF TabOrder = 4 OnClick = CB_InscrireShell_FolderClick end + object CB_InscrireShell_SeparateInstance: TCheckBox + Left = 18 + Top = 104 + Width = 639 + Height = 17 + Caption = 'Open each item in a separate instance' + TabOrder = 8 + Visible = False + OnClick = CB_InscrireShell_FolderClick + end end object Setup_Advanced: TTabSheet Caption = 'Advanced' diff --git a/Source/GUI/VCL/GUI_Preferences.h b/Source/GUI/VCL/GUI_Preferences.h index a78cb2451..a8f1eb764 100644 --- a/Source/GUI/VCL/GUI_Preferences.h +++ b/Source/GUI/VCL/GUI_Preferences.h @@ -75,6 +75,7 @@ class TPreferencesF : public TForm TCheckBox *CB_InscrireShell; TCheckBox *CB_InscrireShell_Folder; TCheckBox *Advanced_LegacyStreamDisplay; + TCheckBox *CB_InscrireShell_SeparateInstance; void __fastcall General_Language_SelChange(TObject *Sender); void __fastcall General_Output_SelChange(TObject *Sender); void __fastcall Custom_EditClick(TObject *Sender); diff --git a/Source/WindowsShellExtension/dllmain.cpp b/Source/WindowsShellExtension/dllmain.cpp index f7856dbd1..9b192b91e 100644 --- a/Source/WindowsShellExtension/dllmain.cpp +++ b/Source/WindowsShellExtension/dllmain.cpp @@ -552,8 +552,64 @@ struct ExplorerCommandHandler : public winrt::implements item; + auto result = items->GetItemAt(i, item.put()); + if (SUCCEEDED(result)) { + wil::unique_cotaskmem_string path; + result = item->GetDisplayName(SIGDN_FILESYSPATH, &path); + if (SUCCEEDED(result)) { + std::filesystem::path filepath{ path.get() }; + // Resolve shortcuts + if (filepath.extension().string().compare(".url") == 0) { + std::string url; + if (ExtractUrlFromShortcut(filepath, url)) + filepath = url; + } + if (filepath.extension().string().compare(".lnk") == 0) { + WCHAR target_path[MAX_PATH]; + if (SUCCEEDED(ResolveIt(nullptr, filepath.wstring().c_str(), target_path, sizeof(target_path)))) + filepath = target_path; + } + auto command{ wil::str_printf(LR"-("%s" %s)-", module_path.c_str(), QuoteForCommandLineArg(filepath.wstring()).c_str()) }; + wil::unique_process_information process_info; + STARTUPINFOW startup_info = { sizeof(startup_info) }; + RETURN_IF_WIN32_BOOL_FALSE(CreateProcessW( + nullptr, + command.data(), + nullptr /* lpProcessAttributes */, + nullptr /* lpThreadAttributes */, + false /* bInheritHandles */, + CREATE_NO_WINDOW, + nullptr, + nullptr, + &startup_info, + &process_info)); + } + } + } + return S_OK; + } + // Prepare cmd line string to invoke application ("path\to\application.exe" "path\to\firstitem" "path\to\nextitem" ...) - auto command = wil::str_printf(LR"-("%s")-", module_path.c_str()); // Path to application.exe + auto command{ wil::str_printf(LR"-("%s")-", module_path.c_str()) }; // Path to application.exe // Add multiple selected files/folders to cmd line as parameters for (DWORD i = 0; i < count; ++i) { winrt::com_ptr item;