Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.

Commit

Permalink
Remove COM DLL dependence, as #72
Browse files Browse the repository at this point in the history
  • Loading branch information
xupefei committed Apr 26, 2015
1 parent 105a374 commit b6b1556
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 30 deletions.
33 changes: 14 additions & 19 deletions LEGUI/AppConfig.xaml.cs
Expand Up @@ -5,8 +5,8 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices.ComTypes;
using System.Windows;
using IWshRuntimeLibrary;
using LECommonLibrary;
using File = System.IO.File;

Expand Down Expand Up @@ -74,26 +74,21 @@ private void CreateShortcut(string path)
{
try
{
var shortcut =
new WshShell().CreateShortcut(string.Format("{0}\\{1}.lnk",
Environment.GetFolderPath(Environment.SpecialFolder
.DesktopDirectory),
Path.GetFileNameWithoutExtension(path))) as IWshShortcut;
IShellLink link = (IShellLink)new ShellLink();

if (shortcut == null)
{
MessageBox.Show("Create shortcut error", "LE", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
link.SetPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"LEProc.exe"));
link.SetArguments(String.Format("-run \"{0}\"", path));
link.SetIconLocation(AssociationReader.GetAssociatedIcon(Path.GetExtension(path)).Replace("%1", path), 0);

link.SetDescription(string.Format("Run {0} with Locale Emulator", Path.GetFileName(path)));
link.SetWorkingDirectory(Path.GetDirectoryName(path));

shortcut.TargetPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
"LEProc.exe");
shortcut.Arguments = String.Format("-run \"{0}\"", path);
shortcut.WorkingDirectory = Path.GetDirectoryName(path);
shortcut.WindowStyle = 1;
shortcut.Description = string.Format("Run {0} with Locale Emulator", Path.GetFileName(path));
shortcut.IconLocation = AssociationReader.GetAssociatedIcon(Path.GetExtension(path)).Replace("%1", path);
shortcut.Save();
IPersistFile file = (IPersistFile)link;
file.Save(
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
Path.GetFileNameWithoutExtension(path) + ".lnk"),
false);
}
catch (Exception e)
{
Expand Down
12 changes: 1 addition & 11 deletions LEGUI/LEGUI.csproj
Expand Up @@ -81,6 +81,7 @@
<Compile Include="AppConfig.xaml.cs">
<DependentUpon>AppConfig.xaml</DependentUpon>
</Compile>
<Compile Include="ShellLink.cs" />
<Page Include="InputBox.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -150,17 +151,6 @@
<EmbedInteropTypes>False</EmbedInteropTypes>
</ProjectReference>
</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>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.1">
<Visible>False</Visible>
Expand Down
45 changes: 45 additions & 0 deletions LEGUI/ShellLink.cs
@@ -0,0 +1,45 @@
using System;
using System.Runtime.InteropServices;
using System.Text;

namespace LEGUI
{
[ComImport]
[Guid("00021401-0000-0000-C000-000000000046")]
internal class ShellLink
{
}

[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("000214F9-0000-0000-C000-000000000046")]
internal interface IShellLink
{
void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile,
int cchMaxPath,
out IntPtr pfd,
int fFlags);

void GetIDList(out IntPtr ppidl);
void SetIDList(IntPtr pidl);
void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName);
void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath);
void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath);
void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
void GetHotkey(out short pwHotkey);
void SetHotkey(short wHotkey);
void GetShowCmd(out int piShowCmd);
void SetShowCmd(int iShowCmd);

void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath,
int cchIconPath,
out int piIcon);

void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved);
void Resolve(IntPtr hwnd, int fFlags);
void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
}
}

0 comments on commit b6b1556

Please sign in to comment.