Fixes for Mono

This commit is contained in:
2015-09-24 06:09:09 +01:00
parent 34b152ba15
commit c734ad85fd
3 changed files with 19 additions and 11 deletions

View File

@@ -66,7 +66,7 @@ namespace ImageCrusher
private void btnCrush_Click(object sender, EventArgs e)
{
string path=txtPath.Text;
string path = txtPath.Text;
if (!Directory.Exists(path))
{
MessageBox.Show("El directorio no existe");

View File

@@ -39,7 +39,6 @@
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />

View File

@@ -13,20 +13,29 @@ namespace ImageCrusher
private static bool CreateShortcut(string shortcut, string exe, string dir)
{
bool created = false;
Type t = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8")); //Windows Script Host Shell Object
object shell = Activator.CreateInstance(t);
Type shellType = null;
object shell = null;
try
{
object lnk = t.InvokeMember("CreateShortcut", BindingFlags.InvokeMethod, null, shell, new object[] { shortcut });
shellType = Type.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8")); //Windows Script Host Shell Object
shell = Activator.CreateInstance(shellType);
}
catch (Exception)
{
return created;
}
try
{
object lnk = shellType.InvokeMember("CreateShortcut", BindingFlags.InvokeMethod, null, shell, new object[] { shortcut });
try
{
string targetPath = (string)t.InvokeMember("TargetPath", BindingFlags.GetProperty, null, lnk, null);
string targetPath = (string)shellType.InvokeMember("TargetPath", BindingFlags.GetProperty, null, lnk, null);
if (targetPath != exe)
{
t.InvokeMember("TargetPath", BindingFlags.SetProperty, null, lnk, new object[] { exe });
t.InvokeMember("WorkingDirectory", BindingFlags.SetProperty, null, lnk, new object[] { dir });
t.InvokeMember("IconLocation", BindingFlags.SetProperty, null, lnk, new object[] { String.Format("{0}, 1", exe) });
t.InvokeMember("Save", BindingFlags.InvokeMethod, null, lnk, null);
shellType.InvokeMember("TargetPath", BindingFlags.SetProperty, null, lnk, new object[] { exe });
shellType.InvokeMember("WorkingDirectory", BindingFlags.SetProperty, null, lnk, new object[] { dir });
shellType.InvokeMember("IconLocation", BindingFlags.SetProperty, null, lnk, new object[] { String.Format("{0}, 1", exe) });
shellType.InvokeMember("Save", BindingFlags.InvokeMethod, null, lnk, null);
created = true;
}
}
@@ -44,7 +53,7 @@ namespace ImageCrusher
private static bool InstallSendToShortcut()
{
String shortcutPath=String.Format("{0}\\ImageCrusher.lnk",Environment.GetFolderPath(Environment.SpecialFolder.SendTo));
String shortcutPath = String.Format("{0}\\ImageCrusher.lnk", Environment.GetFolderPath(Environment.SpecialFolder.SendTo));
string exeName = Path.GetFileNameWithoutExtension(Application.ExecutablePath);
string exePath = Path.GetDirectoryName(Application.ExecutablePath);
return CreateShortcut(shortcutPath, string.Format("{0}\\{1}.exe", exePath, exeName), exePath);