mirror of
https://github.com/cemu-project/DS4Windows.git
synced 2024-12-23 23:21:49 +01:00
Finally found good config for removing IWshRuntimeLibrary dependency
Related to issue #151.
This commit is contained in:
parent
dc18449179
commit
b3c9796fbb
@ -7,6 +7,9 @@ using System.IO;
|
||||
|
||||
using System.Xml;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DS4Windows
|
||||
{
|
||||
@ -384,7 +387,7 @@ namespace DS4Windows
|
||||
bnAddPrograms.Text = Properties.Resources.Loading;
|
||||
bnAddPrograms.Enabled = false;
|
||||
cMSPrograms.Items.Remove(addSteamGamesToolStripMenuItem);
|
||||
await System.Threading.Tasks.Task.Run(() => GetApps(steamgamesdir));
|
||||
await Task.Run(() => GetApps(steamgamesdir));
|
||||
addLoadedApps();
|
||||
}
|
||||
|
||||
@ -395,7 +398,7 @@ namespace DS4Windows
|
||||
{
|
||||
bnAddPrograms.Text = Properties.Resources.Loading;
|
||||
bnAddPrograms.Enabled = false;
|
||||
await System.Threading.Tasks.Task.Run(() => GetApps(fbd.SelectedPath));
|
||||
await Task.Run(() => GetApps(fbd.SelectedPath));
|
||||
addLoadedApps();
|
||||
}
|
||||
}
|
||||
@ -423,7 +426,7 @@ namespace DS4Windows
|
||||
bnAddPrograms.Text = Properties.Resources.Loading;
|
||||
bnAddPrograms.Enabled = false;
|
||||
cMSPrograms.Items.Remove(addOriginGamesToolStripMenuItem);
|
||||
await System.Threading.Tasks.Task.Run(() => GetApps(origingamesdir));
|
||||
await Task.Run(() => GetApps(origingamesdir));
|
||||
addLoadedApps();
|
||||
}
|
||||
|
||||
@ -432,7 +435,7 @@ namespace DS4Windows
|
||||
bnAddPrograms.Text = Properties.Resources.Loading;
|
||||
bnAddPrograms.Enabled = false;
|
||||
cMSPrograms.Items.Remove(addProgramsFromStartMenuToolStripMenuItem);
|
||||
await System.Threading.Tasks.Task.Run(() => GetShortcuts(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Programs"));
|
||||
await Task.Run(() => GetShortcuts(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Programs"));
|
||||
addLoadedApps();
|
||||
}
|
||||
|
||||
@ -474,35 +477,57 @@ namespace DS4Windows
|
||||
public static string ResolveShortcut(string filePath)
|
||||
{
|
||||
// IWshRuntimeLibrary is in the COM library "Windows Script Host Object Model"
|
||||
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
|
||||
//IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
|
||||
Type t = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8")); // Windows Script Host Shell Object
|
||||
dynamic shell = Activator.CreateInstance(t);
|
||||
string result;
|
||||
|
||||
try
|
||||
{
|
||||
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath);
|
||||
return shortcut.TargetPath;
|
||||
//IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath);
|
||||
var shortcut = shell.CreateShortcut(filePath);
|
||||
result = shortcut.TargetPath;
|
||||
Marshal.FinalReleaseComObject(shortcut);
|
||||
}
|
||||
catch (COMException)
|
||||
{
|
||||
// A COMException is thrown if the file is not a valid shortcut (.lnk) file
|
||||
return null;
|
||||
result = null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FinalReleaseComObject(shell);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string ResolveShortcutAndArgument(string filePath)
|
||||
{
|
||||
// IWshRuntimeLibrary is in the COM library "Windows Script Host Object Model"
|
||||
IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
|
||||
//IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
|
||||
Type t = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8")); // Windows Script Host Shell Object
|
||||
dynamic shell = Activator.CreateInstance(t);
|
||||
string result;
|
||||
|
||||
try
|
||||
{
|
||||
IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath);
|
||||
return shortcut.TargetPath + " " + shortcut.Arguments;
|
||||
//IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath);
|
||||
var shortcut = shell.CreateShortcut(filePath);
|
||||
result = shortcut.TargetPath + " " + shortcut.Arguments;
|
||||
Marshal.FinalReleaseComObject(shortcut);
|
||||
}
|
||||
catch (COMException)
|
||||
{
|
||||
// A COMException is thrown if the file is not a valid shortcut (.lnk) file
|
||||
return null;
|
||||
result = null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FinalReleaseComObject(shell);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void cBTurnOffDS4W_CheckedChanged(object sender, EventArgs e)
|
||||
|
@ -1116,17 +1116,6 @@
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<COMReference Include="IWshRuntimeLibrary">
|
||||
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
|
||||
<VersionMajor>1</VersionMajor>
|
||||
<VersionMinor>0</VersionMinor>
|
||||
<Lcid>0</Lcid>
|
||||
<WrapperTool>tlbimp</WrapperTool>
|
||||
<Isolated>False</Isolated>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="HidLibrary\LICENSE" />
|
||||
<Content Include="Resources\360 fades.png" />
|
||||
|
Loading…
Reference in New Issue
Block a user