Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ShellExt: Option for separate instance #1002

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Source/GUI/Qt/prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
70 changes: 42 additions & 28 deletions Source/GUI/Qt/prefs.ui
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,50 @@
<property name="sizeConstraint">
<enum>QLayout::SizeConstraint::SetFixedSize</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Default View</string>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_defaultview">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<property name="leftMargin">
<number>25</number>
</property>
<item>
<widget class="QCheckBox" name="shellExtension_separateInstance">
<property name="text">
<string>Open each item in a separate instance</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="shellInfoTip">
<property name="text">
<string>Shell InfoTip</string>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
<item row="2" column="0">
<widget class="QCheckBox" name="shellExtension">
<property name="text">
<string>Shell extension</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Default View</string>
</property>
</spacer>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkForNewVersion">
Expand All @@ -154,22 +172,18 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="shellExtension">
<property name="text">
<string>Shell extension</string>
<item row="5" column="0">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_defaultview">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</widget>
</spacer>
</item>
</layout>
</widget>
Expand Down
31 changes: 31 additions & 0 deletions Source/GUI/VCL/GUI_Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -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();
Expand Down
39 changes: 25 additions & 14 deletions Source/GUI/VCL/GUI_Preferences.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ object PreferencesF: TPreferencesF
TabOrder = 1
OnChange = TreeChange
Items.NodeData = {
0302000000280000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF000000
00010000000105530065007400750070002E0000000000000000000000FFFFFF
FFFFFFFFFFFFFFFFFF0000000000000000010841006400760061006E00630065
006400300000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000000005
000000010943007500730074006F006D0069007A006500280000000000000000
000000FFFFFFFFFFFFFFFFFFFFFFFF0000000000000000010553006800650065
007400340000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000000000
000000010B540072006500650020002600200054006500780074003400000000
00000000000000FFFFFFFFFFFFFFFFFFFFFFFF0000000000000000010B430075
00730074006F006D0020007400650078007400280000000000000000000000FF
FFFFFFFFFFFFFFFFFFFFFF00000000000000000105470072006100700068002E
0000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF000000000000000001
084C0061006E0067007500610067006500}
070200000009540054007200650065004E006F00640065002900000000000000
00000000FFFFFFFFFFFFFFFFFFFFFFFF00000000000100000001055300650074
007500700000002F0000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF00
0000000000000000010841006400760061006E00630065006400000031000000
0000000000000000FFFFFFFFFFFFFFFFFFFFFFFF000000000005000000010943
007500730074006F006D0069007A0065000000290000000000000000000000FF
FFFFFFFFFFFFFFFFFFFFFF000000000000000000010553006800650065007400
0000350000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF000000000000
000000010B540072006500650020002600200054006500780074000000350000
000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF000000000000000000010B
43007500730074006F006D002000740065007800740000002900000000000000
00000000FFFFFFFFFFFFFFFFFFFFFFFF00000000000000000001054700720061
007000680000002F0000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF00
000000000000000001084C0061006E0067007500610067006500}
end
object Cancel: TButton
Left = 593
Expand Down Expand Up @@ -145,7 +146,7 @@ object PreferencesF: TPreferencesF
end
object CB_InfoTip: TCheckBox
Left = 2
Top = 104
Top = 120
Width = 655
Height = 18
Caption =
Expand Down Expand Up @@ -176,6 +177,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'
Expand Down
1 change: 1 addition & 0 deletions Source/GUI/VCL/GUI_Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 44 additions & 0 deletions Source/WindowsShellExtension/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,50 @@ struct ExplorerCommandHandler : public winrt::implements<ExplorerCommandHandler,
module_path = module_path.remove_filename();
module_path /= exe_filename;

// Option for separate instance
bool separate_instance = false;
try {
#ifdef MEDIAINFO_QT
if (RegGetBool(HKEY_CURRENT_USER, L"Software\\MediaArea.net\\MediaInfo", L"shellExtension_separateInstance"))
#else
if (RegGetDword(HKEY_CURRENT_USER, L"Software\\MediaArea\\MediaInfo", L"ShellExtension_SeparateInstance"))
#endif // MEDIAINFO_QT
{
separate_instance = true;
}
}
catch (...) {
// Error reading reg, default same instance
}
if (separate_instance) {
// Invoke application, one instance per item
for (DWORD i = 0; i < count; ++i) {
winrt::com_ptr<IShellItem> 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)) {
auto command{ wil::str_printf<std::wstring>(LR"-("%s" %s)-", module_path.c_str(), QuoteForCommandLineArg(path.get()).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<std::wstring>(LR"-("%s")-", module_path.c_str()); // Path to application.exe
// Add multiple selected files/folders to cmd line as parameters
Expand Down
Loading