Skip to content

Commit

Permalink
Windows GUI: Support new shell extension
Browse files Browse the repository at this point in the history
  • Loading branch information
cjee21 committed Nov 18, 2024
1 parent 9adcb57 commit b7ce8ff
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
45 changes: 41 additions & 4 deletions Source/Common/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,43 @@ int Preferences::ExplorerShell()
}
}

//Controls for legacy shell extension
int32s LegacyShellExtension = Config.Read(__T("ShellExtension")).To_int32s();
int32s LegacyShellExtension_Folder = Config.Read(__T("ShellExtension_Folder")).To_int32s();

//Control writing registry for modern IExplorerCommand-based shell extension
bool ModernShellExtensionUsed = false;

//Check presence of modern IExplorerCommand-based shell extension and handle things accordingly
TRegistry* ModernReg = new TRegistry;
ModernReg->RootKey = HKEY_CLASSES_ROOT;
try {
//If modern shell extension is installed
if (ModernReg->OpenKeyReadOnly(__T("PackagedCom\\ClassIndex\\{20669675-B281-4C4F-94FB-CB6FD3995545}"))) {
LegacyShellExtension = 0; //Disable legacy shell extension
LegacyShellExtension_Folder = 0; //Disable legacy shell extension
ModernShellExtensionUsed = true; //Need to control modern shell extension
Config(__T("ShellExtension_Folder")) = __T("1"); //Disabling ShellExtension_Folder not implemented
ModernReg->CloseKey();
}
} catch (...) {}
delete ModernReg;

//Control modern IExplorerCommand-based shell extension
if (ModernShellExtensionUsed) {
TRegistry* ModernShellExtension = new TRegistry(KEY_WRITE);
try {
if (ModernShellExtension->OpenKey(__T("Software\\MediaArea\\MediaInfo"), true)) {
if (Config.Read(__T("ShellExtension")).To_int32s())
ModernShellExtension->DeleteValue("ShellExtension");
else
ModernShellExtension->WriteInteger("ShellExtension", 0);
ModernShellExtension->CloseKey();
}
} catch (...) {}
delete ModernShellExtension;
}

bool IsChanged=false;
if ( MajorVersion>=6 //Windows Vista or more
|| (MajorVersion==5 && MinorVersion>=1)) //WinXP or more in 5.x family
Expand Down Expand Up @@ -863,22 +900,22 @@ int Preferences::ExplorerShell()
ExplorerShell_Edit("SystemFileAssociations\\video", 0, IsChanged);

//Adding/removing to SystemFileAssociations
int32s ShellExtension=Config.Read(__T("ShellExtension")).To_int32s();
int32s ShellExtension=LegacyShellExtension;
for (size_t I1=0; I1<List.size(); I1++)
{
//Remove shell ext except "Folder"
if (List(I1, 0)!=__T("Folder"))
ExplorerShell_Edit((__T("Software\\Classes\\SystemFileAssociations\\")+List(I1, 0)).c_str(), ShellExtension, IsChanged);
}
ExplorerShell_Edit("Software\\Classes\\Directory", Config.Read(__T("ShellExtension_Folder")).To_int32s(), IsChanged);
ExplorerShell_Edit("Software\\Classes\\Directory", LegacyShellExtension_Folder, IsChanged);
}
else
{
int32s ShellExtension=Config.Read(__T("ShellExtension")).To_int32s();
int32s ShellExtension=LegacyShellExtension;
for (size_t I1=0; I1<List.size(); I1++)
{
if (List(I1, 0)==__T("Folder"))
ShellExtension=Config.Read(__T("ShellExtension_Folder")).To_int32s();
ShellExtension=LegacyShellExtension_Folder;

//Open (or create) a extension. Create only if Shell extension is wanted
if (Reg->OpenKey(List(I1, 0).c_str(), ShellExtension))
Expand Down
11 changes: 11 additions & 0 deletions Source/GUI/VCL/GUI_Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,17 @@ void __fastcall TPreferencesF::Setup_GeneralShow(TObject *Sender)
CB_InscrireShell->Checked=Prefs->Config(__T("ShellExtension")).To_int32s(); //Lecture Shell extension
CB_InscrireShell_Folder->Checked=Prefs->Config(__T("ShellExtension_Folder")).To_int32s(); //Lecture Shell extension
CB_InfoTip->Checked=Prefs->Config(__T("ShellInfoTip")).To_int32s(); //Lecture Shell extension

//Disable InscrireShell_Folder setting if modern IExplorerCommand-based shell extension is installed (not implemented)
TRegistry* ModernReg=new TRegistry;
ModernReg->RootKey = HKEY_CLASSES_ROOT;
try {
if (ModernReg->OpenKeyReadOnly(__T("PackagedCom\\ClassIndex\\{20669675-B281-4C4F-94FB-CB6FD3995545}"))) {
CB_InscrireShell_Folder->Enabled = false;
ModernReg->CloseKey();
}
} catch (...) {}
delete ModernReg;
}

//---------------------------------------------------------------------------
Expand Down

0 comments on commit b7ce8ff

Please sign in to comment.