Changeset 13 for Common/ExtTools.cs
- Timestamp:
- Feb 8, 2021, 4:23:17 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/ExtTools.cs
r8 r13 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 1 using System; 6 2 using System.IO; 7 3 using System.Diagnostics; 8 4 using System.Windows.Forms; 5 using Microsoft.Win32; 6 using System.Runtime.InteropServices; 9 7 10 8 namespace Common … … 12 10 static class ExtTools 13 11 { 14 public static string compareProgram;15 public static string compareAttributes;12 public static string CompareProgram; 13 public static string CompareAttributes; 16 14 17 15 static ExtTools() 18 16 { 19 17 // Autodetect location of Beyond Compare executable 20 compareProgram = "C:\\Program Files\\Beyond Compare 4\\BCompare.exe";21 if (!File.Exists( compareProgram)) compareProgram = "C:\\Program Files (x86)\\Beyond Compare 4\\BCompare.exe";22 if (!File.Exists( compareProgram)) compareProgram = "C:\\Program Files\\Beyond Compare 3\\BCompare.exe";23 if (!File.Exists( compareProgram)) compareProgram = "C:\\Program Files (x86)\\Beyond Compare 3\\BCompare.exe";18 CompareProgram = "C:\\Program Files\\Beyond Compare 4\\BCompare.exe"; 19 if (!File.Exists(CompareProgram)) CompareProgram = "C:\\Program Files (x86)\\Beyond Compare 4\\BCompare.exe"; 20 if (!File.Exists(CompareProgram)) CompareProgram = "C:\\Program Files\\Beyond Compare 3\\BCompare.exe"; 21 if (!File.Exists(CompareProgram)) CompareProgram = "C:\\Program Files (x86)\\Beyond Compare 3\\BCompare.exe"; 24 22 25 compareAttributes = "\"<<left_file>>\" \"<<right_file>>\"";23 CompareAttributes = "\"<<left_file>>\" \"<<right_file>>\""; 26 24 } 27 25 … … 29 27 { 30 28 return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + 31 System.Windows.Forms.Application.ProductName + "\\Temp";29 Application.ProductName + "\\Temp"; 32 30 } 33 31 … … 51 49 { 52 50 // Execute comparison process 53 string att s = compareAttributes;54 att s = atts.Replace("<<left_file>>", filenameLeft);55 att s = atts.Replace("<<right_file>>", filenameRight);56 ExecuteProgram( compareProgram, atts);51 string attributes = CompareAttributes; 52 attributes = attributes.Replace("<<left_file>>", filenameLeft); 53 attributes = attributes.Replace("<<right_file>>", filenameRight); 54 ExecuteProgram(CompareProgram, attributes); 57 55 } catch (Exception e) 58 56 { 59 MessageBox.Show(e.Message .ToString());57 MessageBox.Show(e.Message); 60 58 } 61 59 } 62 60 63 public static void ExecuteProgram(string executableFileName, string arguments , string workingDirectory = "")61 public static void ExecuteProgram(string executableFileName, string arguments = "", string workingDirectory = "") 64 62 { 65 63 // Execute external process … … 106 104 } 107 105 return output; 108 } 106 } 107 108 public static void SetFileAssociation(string extension, string progId, string openWith, string fileDescription) 109 { 110 RegistryKey BaseKey; 111 RegistryKey OpenMethod; 112 RegistryKey Shell; 113 RegistryKey CurrentUser; 114 115 BaseKey = Registry.ClassesRoot.CreateSubKey(extension); 116 BaseKey?.SetValue("", progId); 117 118 OpenMethod = Registry.ClassesRoot.CreateSubKey(progId); 119 OpenMethod?.SetValue("", fileDescription); 120 OpenMethod?.CreateSubKey("DefaultIcon")?.SetValue("", "\"" + openWith + "\",0"); 121 Shell = OpenMethod?.CreateSubKey("Shell"); 122 Shell?.CreateSubKey("edit")?.CreateSubKey("command")?.SetValue("", "\"" + openWith + "\"" + " \"%1\""); 123 Shell?.CreateSubKey("open")?.CreateSubKey("command")?.SetValue("", "\"" + openWith + "\"" + " \"%1\""); 124 Shell?.Close(); 125 OpenMethod?.Close(); 126 BaseKey?.Close(); 127 128 // Delete explorer override 129 CurrentUser = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\" + extension, true); 130 CurrentUser?.DeleteSubKey("UserChoice", false); 131 CurrentUser?.Close(); 132 133 // Tell explorer the file association has been changed 134 SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero); 135 } 136 137 [DllImport("shell32.dll", CharSet = CharSet.Auto, SetLastError = true)] 138 public static extern void SHChangeNotify(uint wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2); 109 139 } 110 140 }
Note:
See TracChangeset
for help on using the changeset viewer.