diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs new file mode 100755 index 0000000..fbb1aee --- /dev/null +++ b/ShortcutUtil/MainForm.Designer.cs @@ -0,0 +1,90 @@ +namespace ShortcutUtil +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.entryListBox = new System.Windows.Forms.ListBox(); + this.createButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(169, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select default shortcut"; + // + // entryListBox + // + this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.entryListBox.FormattingEnabled = true; + this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Name = "entryListBox"; + this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.TabIndex = 1; + this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); + this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); + // + // createButton + // + this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Name = "createButton"; + this.createButton.Size = new System.Drawing.Size(144, 40); + this.createButton.TabIndex = 2; + this.createButton.Text = "Create Shortcut"; + this.createButton.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AcceptButton = this.createButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 444); + this.Controls.Add(this.createButton); + this.Controls.Add(this.entryListBox); + this.Controls.Add(this.label1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Shown += new System.EventHandler(this.MainForm_Shown); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox entryListBox; + private System.Windows.Forms.Button createButton; + } +} + diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs new file mode 100755 index 0000000..fbb1aee --- /dev/null +++ b/ShortcutUtil/MainForm.Designer.cs @@ -0,0 +1,90 @@ +namespace ShortcutUtil +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.entryListBox = new System.Windows.Forms.ListBox(); + this.createButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(169, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select default shortcut"; + // + // entryListBox + // + this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.entryListBox.FormattingEnabled = true; + this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Name = "entryListBox"; + this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.TabIndex = 1; + this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); + this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); + // + // createButton + // + this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Name = "createButton"; + this.createButton.Size = new System.Drawing.Size(144, 40); + this.createButton.TabIndex = 2; + this.createButton.Text = "Create Shortcut"; + this.createButton.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AcceptButton = this.createButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 444); + this.Controls.Add(this.createButton); + this.Controls.Add(this.entryListBox); + this.Controls.Add(this.label1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Shown += new System.EventHandler(this.MainForm_Shown); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox entryListBox; + private System.Windows.Forms.Button createButton; + } +} + diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs new file mode 100755 index 0000000..cb5990a --- /dev/null +++ b/ShortcutUtil/MainForm.cs @@ -0,0 +1,132 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class MainForm : Form + { + private EntryList entryList; + + private Font defaultFont; + private Font nameFont; + private Brush fontBrush; + + private bool shown = false; + private Size listSizeOffset; + private Point buttonOffset; + + public MainForm(EntryList entryList) + { + InitializeComponent(); + + defaultFont = label1.Font; + nameFont = new Font(defaultFont, FontStyle.Bold); + fontBrush = new SolidBrush(label1.ForeColor); + + this.entryList = entryList; + + entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + } + + private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); + private Icon GetIcon(string file, int index, Size preferred) + { + Tuple key = new Tuple(file, index, preferred); + + + + if (!iconsByFileIndex.ContainsKey(key)) + { + Icon icon = null; + + try + { + icon = new Icon(file, preferred); + + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } catch (Exception) { } + + try + { + icon = IconExtractor.Extract(file, index, true); + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } + catch (Exception) { } + + MessageBox.Show("Couldn't load icon " + index + " from " + file); + return null; + } + + return iconsByFileIndex[key]; + } + + private static readonly Size IconSize = new Size(64, 64); + private static readonly Size ItemPadding = new Size(6, 6); + + private void entryListBox_DrawItem(object sender, DrawItemEventArgs e) + { + e.DrawBackground(); + e.DrawFocusRectangle(); + + if (e.Index >= 0 && e.Index < entryList.Entries.Count) + { + Rectangle iconBounds = new Rectangle(Point.Add(e.Bounds.Location, ItemPadding), IconSize); + + Size textSize = new Size(0, nameFont.Height + 2); + + Entry entry = entryList.Entries[e.Index]; + e.Graphics.DrawIcon(GetIcon(entry.Icon, entry.IconIndex, IconSize), iconBounds); + + PointF textLocation = PointF.Add(e.Bounds.Location, new Size(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width)); + + e.Graphics.DrawString(e.Index + ": " + entry.Name, nameFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Target, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Description, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + } + } + + private void entryListBox_MeasureItem(object sender, MeasureItemEventArgs e) + { + e.ItemHeight = Size.Add(IconSize, new Size(0, ItemPadding.Height * 2)).Height; + } + + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (shown) + { + entryListBox.Size = Size.Subtract(Size, listSizeOffset); + createButton.Location = Point.Add(buttonOffset, entryListBox.Size); + } + } + + private void MainForm_Shown(object sender, EventArgs e) + { + listSizeOffset = Size.Subtract(Size, entryListBox.Size); + buttonOffset = Point.Subtract(createButton.Location, entryListBox.Size); + + shown = true; + } + } +} diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs new file mode 100755 index 0000000..fbb1aee --- /dev/null +++ b/ShortcutUtil/MainForm.Designer.cs @@ -0,0 +1,90 @@ +namespace ShortcutUtil +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.entryListBox = new System.Windows.Forms.ListBox(); + this.createButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(169, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select default shortcut"; + // + // entryListBox + // + this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.entryListBox.FormattingEnabled = true; + this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Name = "entryListBox"; + this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.TabIndex = 1; + this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); + this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); + // + // createButton + // + this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Name = "createButton"; + this.createButton.Size = new System.Drawing.Size(144, 40); + this.createButton.TabIndex = 2; + this.createButton.Text = "Create Shortcut"; + this.createButton.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AcceptButton = this.createButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 444); + this.Controls.Add(this.createButton); + this.Controls.Add(this.entryListBox); + this.Controls.Add(this.label1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Shown += new System.EventHandler(this.MainForm_Shown); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox entryListBox; + private System.Windows.Forms.Button createButton; + } +} + diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs new file mode 100755 index 0000000..cb5990a --- /dev/null +++ b/ShortcutUtil/MainForm.cs @@ -0,0 +1,132 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class MainForm : Form + { + private EntryList entryList; + + private Font defaultFont; + private Font nameFont; + private Brush fontBrush; + + private bool shown = false; + private Size listSizeOffset; + private Point buttonOffset; + + public MainForm(EntryList entryList) + { + InitializeComponent(); + + defaultFont = label1.Font; + nameFont = new Font(defaultFont, FontStyle.Bold); + fontBrush = new SolidBrush(label1.ForeColor); + + this.entryList = entryList; + + entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + } + + private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); + private Icon GetIcon(string file, int index, Size preferred) + { + Tuple key = new Tuple(file, index, preferred); + + + + if (!iconsByFileIndex.ContainsKey(key)) + { + Icon icon = null; + + try + { + icon = new Icon(file, preferred); + + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } catch (Exception) { } + + try + { + icon = IconExtractor.Extract(file, index, true); + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } + catch (Exception) { } + + MessageBox.Show("Couldn't load icon " + index + " from " + file); + return null; + } + + return iconsByFileIndex[key]; + } + + private static readonly Size IconSize = new Size(64, 64); + private static readonly Size ItemPadding = new Size(6, 6); + + private void entryListBox_DrawItem(object sender, DrawItemEventArgs e) + { + e.DrawBackground(); + e.DrawFocusRectangle(); + + if (e.Index >= 0 && e.Index < entryList.Entries.Count) + { + Rectangle iconBounds = new Rectangle(Point.Add(e.Bounds.Location, ItemPadding), IconSize); + + Size textSize = new Size(0, nameFont.Height + 2); + + Entry entry = entryList.Entries[e.Index]; + e.Graphics.DrawIcon(GetIcon(entry.Icon, entry.IconIndex, IconSize), iconBounds); + + PointF textLocation = PointF.Add(e.Bounds.Location, new Size(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width)); + + e.Graphics.DrawString(e.Index + ": " + entry.Name, nameFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Target, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Description, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + } + } + + private void entryListBox_MeasureItem(object sender, MeasureItemEventArgs e) + { + e.ItemHeight = Size.Add(IconSize, new Size(0, ItemPadding.Height * 2)).Height; + } + + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (shown) + { + entryListBox.Size = Size.Subtract(Size, listSizeOffset); + createButton.Location = Point.Add(buttonOffset, entryListBox.Size); + } + } + + private void MainForm_Shown(object sender, EventArgs e) + { + listSizeOffset = Size.Subtract(Size, entryListBox.Size); + buttonOffset = Point.Subtract(createButton.Location, entryListBox.Size); + + shown = true; + } + } +} diff --git a/ShortcutUtil/MainForm.resx b/ShortcutUtil/MainForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs new file mode 100755 index 0000000..fbb1aee --- /dev/null +++ b/ShortcutUtil/MainForm.Designer.cs @@ -0,0 +1,90 @@ +namespace ShortcutUtil +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.entryListBox = new System.Windows.Forms.ListBox(); + this.createButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(169, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select default shortcut"; + // + // entryListBox + // + this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.entryListBox.FormattingEnabled = true; + this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Name = "entryListBox"; + this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.TabIndex = 1; + this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); + this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); + // + // createButton + // + this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Name = "createButton"; + this.createButton.Size = new System.Drawing.Size(144, 40); + this.createButton.TabIndex = 2; + this.createButton.Text = "Create Shortcut"; + this.createButton.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AcceptButton = this.createButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 444); + this.Controls.Add(this.createButton); + this.Controls.Add(this.entryListBox); + this.Controls.Add(this.label1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Shown += new System.EventHandler(this.MainForm_Shown); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox entryListBox; + private System.Windows.Forms.Button createButton; + } +} + diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs new file mode 100755 index 0000000..cb5990a --- /dev/null +++ b/ShortcutUtil/MainForm.cs @@ -0,0 +1,132 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class MainForm : Form + { + private EntryList entryList; + + private Font defaultFont; + private Font nameFont; + private Brush fontBrush; + + private bool shown = false; + private Size listSizeOffset; + private Point buttonOffset; + + public MainForm(EntryList entryList) + { + InitializeComponent(); + + defaultFont = label1.Font; + nameFont = new Font(defaultFont, FontStyle.Bold); + fontBrush = new SolidBrush(label1.ForeColor); + + this.entryList = entryList; + + entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + } + + private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); + private Icon GetIcon(string file, int index, Size preferred) + { + Tuple key = new Tuple(file, index, preferred); + + + + if (!iconsByFileIndex.ContainsKey(key)) + { + Icon icon = null; + + try + { + icon = new Icon(file, preferred); + + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } catch (Exception) { } + + try + { + icon = IconExtractor.Extract(file, index, true); + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } + catch (Exception) { } + + MessageBox.Show("Couldn't load icon " + index + " from " + file); + return null; + } + + return iconsByFileIndex[key]; + } + + private static readonly Size IconSize = new Size(64, 64); + private static readonly Size ItemPadding = new Size(6, 6); + + private void entryListBox_DrawItem(object sender, DrawItemEventArgs e) + { + e.DrawBackground(); + e.DrawFocusRectangle(); + + if (e.Index >= 0 && e.Index < entryList.Entries.Count) + { + Rectangle iconBounds = new Rectangle(Point.Add(e.Bounds.Location, ItemPadding), IconSize); + + Size textSize = new Size(0, nameFont.Height + 2); + + Entry entry = entryList.Entries[e.Index]; + e.Graphics.DrawIcon(GetIcon(entry.Icon, entry.IconIndex, IconSize), iconBounds); + + PointF textLocation = PointF.Add(e.Bounds.Location, new Size(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width)); + + e.Graphics.DrawString(e.Index + ": " + entry.Name, nameFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Target, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Description, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + } + } + + private void entryListBox_MeasureItem(object sender, MeasureItemEventArgs e) + { + e.ItemHeight = Size.Add(IconSize, new Size(0, ItemPadding.Height * 2)).Height; + } + + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (shown) + { + entryListBox.Size = Size.Subtract(Size, listSizeOffset); + createButton.Location = Point.Add(buttonOffset, entryListBox.Size); + } + } + + private void MainForm_Shown(object sender, EventArgs e) + { + listSizeOffset = Size.Subtract(Size, entryListBox.Size); + buttonOffset = Point.Subtract(createButton.Location, entryListBox.Size); + + shown = true; + } + } +} diff --git a/ShortcutUtil/MainForm.resx b/ShortcutUtil/MainForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs new file mode 100755 index 0000000..3a962d4 --- /dev/null +++ b/ShortcutUtil/Program.cs @@ -0,0 +1,52 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + string[] args = Environment.GetCommandLineArgs(); + + if (args.Length < 2) + { + MessageBox.Show("Drag a shortcuts.json onto this executable"); + return; + } + + EntryList entryList = null; + try + { + entryList = EntryList.FromFile(args[1]); + } + catch (Exception e) + { + MessageBox.Show("Couldn't load settings file " + args[1] + "\n" + e); + return; + } + + if (entryList.Entries.Count == 0) + { + MessageBox.Show("No shorcuts in that settings file!"); + return; + } + + Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm(entryList)); + } + } +} diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs new file mode 100755 index 0000000..fbb1aee --- /dev/null +++ b/ShortcutUtil/MainForm.Designer.cs @@ -0,0 +1,90 @@ +namespace ShortcutUtil +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.entryListBox = new System.Windows.Forms.ListBox(); + this.createButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(169, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select default shortcut"; + // + // entryListBox + // + this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.entryListBox.FormattingEnabled = true; + this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Name = "entryListBox"; + this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.TabIndex = 1; + this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); + this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); + // + // createButton + // + this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Name = "createButton"; + this.createButton.Size = new System.Drawing.Size(144, 40); + this.createButton.TabIndex = 2; + this.createButton.Text = "Create Shortcut"; + this.createButton.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AcceptButton = this.createButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 444); + this.Controls.Add(this.createButton); + this.Controls.Add(this.entryListBox); + this.Controls.Add(this.label1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Shown += new System.EventHandler(this.MainForm_Shown); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox entryListBox; + private System.Windows.Forms.Button createButton; + } +} + diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs new file mode 100755 index 0000000..cb5990a --- /dev/null +++ b/ShortcutUtil/MainForm.cs @@ -0,0 +1,132 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class MainForm : Form + { + private EntryList entryList; + + private Font defaultFont; + private Font nameFont; + private Brush fontBrush; + + private bool shown = false; + private Size listSizeOffset; + private Point buttonOffset; + + public MainForm(EntryList entryList) + { + InitializeComponent(); + + defaultFont = label1.Font; + nameFont = new Font(defaultFont, FontStyle.Bold); + fontBrush = new SolidBrush(label1.ForeColor); + + this.entryList = entryList; + + entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + } + + private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); + private Icon GetIcon(string file, int index, Size preferred) + { + Tuple key = new Tuple(file, index, preferred); + + + + if (!iconsByFileIndex.ContainsKey(key)) + { + Icon icon = null; + + try + { + icon = new Icon(file, preferred); + + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } catch (Exception) { } + + try + { + icon = IconExtractor.Extract(file, index, true); + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } + catch (Exception) { } + + MessageBox.Show("Couldn't load icon " + index + " from " + file); + return null; + } + + return iconsByFileIndex[key]; + } + + private static readonly Size IconSize = new Size(64, 64); + private static readonly Size ItemPadding = new Size(6, 6); + + private void entryListBox_DrawItem(object sender, DrawItemEventArgs e) + { + e.DrawBackground(); + e.DrawFocusRectangle(); + + if (e.Index >= 0 && e.Index < entryList.Entries.Count) + { + Rectangle iconBounds = new Rectangle(Point.Add(e.Bounds.Location, ItemPadding), IconSize); + + Size textSize = new Size(0, nameFont.Height + 2); + + Entry entry = entryList.Entries[e.Index]; + e.Graphics.DrawIcon(GetIcon(entry.Icon, entry.IconIndex, IconSize), iconBounds); + + PointF textLocation = PointF.Add(e.Bounds.Location, new Size(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width)); + + e.Graphics.DrawString(e.Index + ": " + entry.Name, nameFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Target, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Description, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + } + } + + private void entryListBox_MeasureItem(object sender, MeasureItemEventArgs e) + { + e.ItemHeight = Size.Add(IconSize, new Size(0, ItemPadding.Height * 2)).Height; + } + + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (shown) + { + entryListBox.Size = Size.Subtract(Size, listSizeOffset); + createButton.Location = Point.Add(buttonOffset, entryListBox.Size); + } + } + + private void MainForm_Shown(object sender, EventArgs e) + { + listSizeOffset = Size.Subtract(Size, entryListBox.Size); + buttonOffset = Point.Subtract(createButton.Location, entryListBox.Size); + + shown = true; + } + } +} diff --git a/ShortcutUtil/MainForm.resx b/ShortcutUtil/MainForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs new file mode 100755 index 0000000..3a962d4 --- /dev/null +++ b/ShortcutUtil/Program.cs @@ -0,0 +1,52 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + string[] args = Environment.GetCommandLineArgs(); + + if (args.Length < 2) + { + MessageBox.Show("Drag a shortcuts.json onto this executable"); + return; + } + + EntryList entryList = null; + try + { + entryList = EntryList.FromFile(args[1]); + } + catch (Exception e) + { + MessageBox.Show("Couldn't load settings file " + args[1] + "\n" + e); + return; + } + + if (entryList.Entries.Count == 0) + { + MessageBox.Show("No shorcuts in that settings file!"); + return; + } + + Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm(entryList)); + } + } +} diff --git a/ShortcutUtil/Properties/AssemblyInfo.cs b/ShortcutUtil/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..e1dc184 --- /dev/null +++ b/ShortcutUtil/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ShortcutUtil")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ShortcutUtil")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("91bac03d-bbbb-403c-a8b0-2f70497f39ba")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs new file mode 100755 index 0000000..fbb1aee --- /dev/null +++ b/ShortcutUtil/MainForm.Designer.cs @@ -0,0 +1,90 @@ +namespace ShortcutUtil +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.entryListBox = new System.Windows.Forms.ListBox(); + this.createButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(169, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select default shortcut"; + // + // entryListBox + // + this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.entryListBox.FormattingEnabled = true; + this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Name = "entryListBox"; + this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.TabIndex = 1; + this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); + this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); + // + // createButton + // + this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Name = "createButton"; + this.createButton.Size = new System.Drawing.Size(144, 40); + this.createButton.TabIndex = 2; + this.createButton.Text = "Create Shortcut"; + this.createButton.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AcceptButton = this.createButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 444); + this.Controls.Add(this.createButton); + this.Controls.Add(this.entryListBox); + this.Controls.Add(this.label1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Shown += new System.EventHandler(this.MainForm_Shown); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox entryListBox; + private System.Windows.Forms.Button createButton; + } +} + diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs new file mode 100755 index 0000000..cb5990a --- /dev/null +++ b/ShortcutUtil/MainForm.cs @@ -0,0 +1,132 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class MainForm : Form + { + private EntryList entryList; + + private Font defaultFont; + private Font nameFont; + private Brush fontBrush; + + private bool shown = false; + private Size listSizeOffset; + private Point buttonOffset; + + public MainForm(EntryList entryList) + { + InitializeComponent(); + + defaultFont = label1.Font; + nameFont = new Font(defaultFont, FontStyle.Bold); + fontBrush = new SolidBrush(label1.ForeColor); + + this.entryList = entryList; + + entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + } + + private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); + private Icon GetIcon(string file, int index, Size preferred) + { + Tuple key = new Tuple(file, index, preferred); + + + + if (!iconsByFileIndex.ContainsKey(key)) + { + Icon icon = null; + + try + { + icon = new Icon(file, preferred); + + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } catch (Exception) { } + + try + { + icon = IconExtractor.Extract(file, index, true); + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } + catch (Exception) { } + + MessageBox.Show("Couldn't load icon " + index + " from " + file); + return null; + } + + return iconsByFileIndex[key]; + } + + private static readonly Size IconSize = new Size(64, 64); + private static readonly Size ItemPadding = new Size(6, 6); + + private void entryListBox_DrawItem(object sender, DrawItemEventArgs e) + { + e.DrawBackground(); + e.DrawFocusRectangle(); + + if (e.Index >= 0 && e.Index < entryList.Entries.Count) + { + Rectangle iconBounds = new Rectangle(Point.Add(e.Bounds.Location, ItemPadding), IconSize); + + Size textSize = new Size(0, nameFont.Height + 2); + + Entry entry = entryList.Entries[e.Index]; + e.Graphics.DrawIcon(GetIcon(entry.Icon, entry.IconIndex, IconSize), iconBounds); + + PointF textLocation = PointF.Add(e.Bounds.Location, new Size(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width)); + + e.Graphics.DrawString(e.Index + ": " + entry.Name, nameFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Target, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Description, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + } + } + + private void entryListBox_MeasureItem(object sender, MeasureItemEventArgs e) + { + e.ItemHeight = Size.Add(IconSize, new Size(0, ItemPadding.Height * 2)).Height; + } + + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (shown) + { + entryListBox.Size = Size.Subtract(Size, listSizeOffset); + createButton.Location = Point.Add(buttonOffset, entryListBox.Size); + } + } + + private void MainForm_Shown(object sender, EventArgs e) + { + listSizeOffset = Size.Subtract(Size, entryListBox.Size); + buttonOffset = Point.Subtract(createButton.Location, entryListBox.Size); + + shown = true; + } + } +} diff --git a/ShortcutUtil/MainForm.resx b/ShortcutUtil/MainForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs new file mode 100755 index 0000000..3a962d4 --- /dev/null +++ b/ShortcutUtil/Program.cs @@ -0,0 +1,52 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + string[] args = Environment.GetCommandLineArgs(); + + if (args.Length < 2) + { + MessageBox.Show("Drag a shortcuts.json onto this executable"); + return; + } + + EntryList entryList = null; + try + { + entryList = EntryList.FromFile(args[1]); + } + catch (Exception e) + { + MessageBox.Show("Couldn't load settings file " + args[1] + "\n" + e); + return; + } + + if (entryList.Entries.Count == 0) + { + MessageBox.Show("No shorcuts in that settings file!"); + return; + } + + Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm(entryList)); + } + } +} diff --git a/ShortcutUtil/Properties/AssemblyInfo.cs b/ShortcutUtil/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..e1dc184 --- /dev/null +++ b/ShortcutUtil/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ShortcutUtil")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ShortcutUtil")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("91bac03d-bbbb-403c-a8b0-2f70497f39ba")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ShortcutUtil/Properties/Resources.Designer.cs b/ShortcutUtil/Properties/Resources.Designer.cs new file mode 100755 index 0000000..52776c1 --- /dev/null +++ b/ShortcutUtil/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShortcutUtil.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShortcutUtil.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs new file mode 100755 index 0000000..fbb1aee --- /dev/null +++ b/ShortcutUtil/MainForm.Designer.cs @@ -0,0 +1,90 @@ +namespace ShortcutUtil +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.entryListBox = new System.Windows.Forms.ListBox(); + this.createButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(169, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select default shortcut"; + // + // entryListBox + // + this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.entryListBox.FormattingEnabled = true; + this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Name = "entryListBox"; + this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.TabIndex = 1; + this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); + this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); + // + // createButton + // + this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Name = "createButton"; + this.createButton.Size = new System.Drawing.Size(144, 40); + this.createButton.TabIndex = 2; + this.createButton.Text = "Create Shortcut"; + this.createButton.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AcceptButton = this.createButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 444); + this.Controls.Add(this.createButton); + this.Controls.Add(this.entryListBox); + this.Controls.Add(this.label1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Shown += new System.EventHandler(this.MainForm_Shown); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox entryListBox; + private System.Windows.Forms.Button createButton; + } +} + diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs new file mode 100755 index 0000000..cb5990a --- /dev/null +++ b/ShortcutUtil/MainForm.cs @@ -0,0 +1,132 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class MainForm : Form + { + private EntryList entryList; + + private Font defaultFont; + private Font nameFont; + private Brush fontBrush; + + private bool shown = false; + private Size listSizeOffset; + private Point buttonOffset; + + public MainForm(EntryList entryList) + { + InitializeComponent(); + + defaultFont = label1.Font; + nameFont = new Font(defaultFont, FontStyle.Bold); + fontBrush = new SolidBrush(label1.ForeColor); + + this.entryList = entryList; + + entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + } + + private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); + private Icon GetIcon(string file, int index, Size preferred) + { + Tuple key = new Tuple(file, index, preferred); + + + + if (!iconsByFileIndex.ContainsKey(key)) + { + Icon icon = null; + + try + { + icon = new Icon(file, preferred); + + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } catch (Exception) { } + + try + { + icon = IconExtractor.Extract(file, index, true); + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } + catch (Exception) { } + + MessageBox.Show("Couldn't load icon " + index + " from " + file); + return null; + } + + return iconsByFileIndex[key]; + } + + private static readonly Size IconSize = new Size(64, 64); + private static readonly Size ItemPadding = new Size(6, 6); + + private void entryListBox_DrawItem(object sender, DrawItemEventArgs e) + { + e.DrawBackground(); + e.DrawFocusRectangle(); + + if (e.Index >= 0 && e.Index < entryList.Entries.Count) + { + Rectangle iconBounds = new Rectangle(Point.Add(e.Bounds.Location, ItemPadding), IconSize); + + Size textSize = new Size(0, nameFont.Height + 2); + + Entry entry = entryList.Entries[e.Index]; + e.Graphics.DrawIcon(GetIcon(entry.Icon, entry.IconIndex, IconSize), iconBounds); + + PointF textLocation = PointF.Add(e.Bounds.Location, new Size(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width)); + + e.Graphics.DrawString(e.Index + ": " + entry.Name, nameFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Target, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Description, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + } + } + + private void entryListBox_MeasureItem(object sender, MeasureItemEventArgs e) + { + e.ItemHeight = Size.Add(IconSize, new Size(0, ItemPadding.Height * 2)).Height; + } + + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (shown) + { + entryListBox.Size = Size.Subtract(Size, listSizeOffset); + createButton.Location = Point.Add(buttonOffset, entryListBox.Size); + } + } + + private void MainForm_Shown(object sender, EventArgs e) + { + listSizeOffset = Size.Subtract(Size, entryListBox.Size); + buttonOffset = Point.Subtract(createButton.Location, entryListBox.Size); + + shown = true; + } + } +} diff --git a/ShortcutUtil/MainForm.resx b/ShortcutUtil/MainForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs new file mode 100755 index 0000000..3a962d4 --- /dev/null +++ b/ShortcutUtil/Program.cs @@ -0,0 +1,52 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + string[] args = Environment.GetCommandLineArgs(); + + if (args.Length < 2) + { + MessageBox.Show("Drag a shortcuts.json onto this executable"); + return; + } + + EntryList entryList = null; + try + { + entryList = EntryList.FromFile(args[1]); + } + catch (Exception e) + { + MessageBox.Show("Couldn't load settings file " + args[1] + "\n" + e); + return; + } + + if (entryList.Entries.Count == 0) + { + MessageBox.Show("No shorcuts in that settings file!"); + return; + } + + Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm(entryList)); + } + } +} diff --git a/ShortcutUtil/Properties/AssemblyInfo.cs b/ShortcutUtil/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..e1dc184 --- /dev/null +++ b/ShortcutUtil/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ShortcutUtil")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ShortcutUtil")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("91bac03d-bbbb-403c-a8b0-2f70497f39ba")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ShortcutUtil/Properties/Resources.Designer.cs b/ShortcutUtil/Properties/Resources.Designer.cs new file mode 100755 index 0000000..52776c1 --- /dev/null +++ b/ShortcutUtil/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShortcutUtil.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShortcutUtil.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/ShortcutUtil/Properties/Resources.resx b/ShortcutUtil/Properties/Resources.resx new file mode 100755 index 0000000..ffecec8 --- /dev/null +++ b/ShortcutUtil/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs new file mode 100755 index 0000000..fbb1aee --- /dev/null +++ b/ShortcutUtil/MainForm.Designer.cs @@ -0,0 +1,90 @@ +namespace ShortcutUtil +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.entryListBox = new System.Windows.Forms.ListBox(); + this.createButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(169, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select default shortcut"; + // + // entryListBox + // + this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.entryListBox.FormattingEnabled = true; + this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Name = "entryListBox"; + this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.TabIndex = 1; + this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); + this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); + // + // createButton + // + this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Name = "createButton"; + this.createButton.Size = new System.Drawing.Size(144, 40); + this.createButton.TabIndex = 2; + this.createButton.Text = "Create Shortcut"; + this.createButton.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AcceptButton = this.createButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 444); + this.Controls.Add(this.createButton); + this.Controls.Add(this.entryListBox); + this.Controls.Add(this.label1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Shown += new System.EventHandler(this.MainForm_Shown); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox entryListBox; + private System.Windows.Forms.Button createButton; + } +} + diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs new file mode 100755 index 0000000..cb5990a --- /dev/null +++ b/ShortcutUtil/MainForm.cs @@ -0,0 +1,132 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class MainForm : Form + { + private EntryList entryList; + + private Font defaultFont; + private Font nameFont; + private Brush fontBrush; + + private bool shown = false; + private Size listSizeOffset; + private Point buttonOffset; + + public MainForm(EntryList entryList) + { + InitializeComponent(); + + defaultFont = label1.Font; + nameFont = new Font(defaultFont, FontStyle.Bold); + fontBrush = new SolidBrush(label1.ForeColor); + + this.entryList = entryList; + + entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + } + + private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); + private Icon GetIcon(string file, int index, Size preferred) + { + Tuple key = new Tuple(file, index, preferred); + + + + if (!iconsByFileIndex.ContainsKey(key)) + { + Icon icon = null; + + try + { + icon = new Icon(file, preferred); + + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } catch (Exception) { } + + try + { + icon = IconExtractor.Extract(file, index, true); + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } + catch (Exception) { } + + MessageBox.Show("Couldn't load icon " + index + " from " + file); + return null; + } + + return iconsByFileIndex[key]; + } + + private static readonly Size IconSize = new Size(64, 64); + private static readonly Size ItemPadding = new Size(6, 6); + + private void entryListBox_DrawItem(object sender, DrawItemEventArgs e) + { + e.DrawBackground(); + e.DrawFocusRectangle(); + + if (e.Index >= 0 && e.Index < entryList.Entries.Count) + { + Rectangle iconBounds = new Rectangle(Point.Add(e.Bounds.Location, ItemPadding), IconSize); + + Size textSize = new Size(0, nameFont.Height + 2); + + Entry entry = entryList.Entries[e.Index]; + e.Graphics.DrawIcon(GetIcon(entry.Icon, entry.IconIndex, IconSize), iconBounds); + + PointF textLocation = PointF.Add(e.Bounds.Location, new Size(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width)); + + e.Graphics.DrawString(e.Index + ": " + entry.Name, nameFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Target, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Description, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + } + } + + private void entryListBox_MeasureItem(object sender, MeasureItemEventArgs e) + { + e.ItemHeight = Size.Add(IconSize, new Size(0, ItemPadding.Height * 2)).Height; + } + + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (shown) + { + entryListBox.Size = Size.Subtract(Size, listSizeOffset); + createButton.Location = Point.Add(buttonOffset, entryListBox.Size); + } + } + + private void MainForm_Shown(object sender, EventArgs e) + { + listSizeOffset = Size.Subtract(Size, entryListBox.Size); + buttonOffset = Point.Subtract(createButton.Location, entryListBox.Size); + + shown = true; + } + } +} diff --git a/ShortcutUtil/MainForm.resx b/ShortcutUtil/MainForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs new file mode 100755 index 0000000..3a962d4 --- /dev/null +++ b/ShortcutUtil/Program.cs @@ -0,0 +1,52 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + string[] args = Environment.GetCommandLineArgs(); + + if (args.Length < 2) + { + MessageBox.Show("Drag a shortcuts.json onto this executable"); + return; + } + + EntryList entryList = null; + try + { + entryList = EntryList.FromFile(args[1]); + } + catch (Exception e) + { + MessageBox.Show("Couldn't load settings file " + args[1] + "\n" + e); + return; + } + + if (entryList.Entries.Count == 0) + { + MessageBox.Show("No shorcuts in that settings file!"); + return; + } + + Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm(entryList)); + } + } +} diff --git a/ShortcutUtil/Properties/AssemblyInfo.cs b/ShortcutUtil/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..e1dc184 --- /dev/null +++ b/ShortcutUtil/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ShortcutUtil")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ShortcutUtil")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("91bac03d-bbbb-403c-a8b0-2f70497f39ba")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ShortcutUtil/Properties/Resources.Designer.cs b/ShortcutUtil/Properties/Resources.Designer.cs new file mode 100755 index 0000000..52776c1 --- /dev/null +++ b/ShortcutUtil/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShortcutUtil.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShortcutUtil.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/ShortcutUtil/Properties/Resources.resx b/ShortcutUtil/Properties/Resources.resx new file mode 100755 index 0000000..ffecec8 --- /dev/null +++ b/ShortcutUtil/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Properties/Settings.Designer.cs b/ShortcutUtil/Properties/Settings.Designer.cs new file mode 100755 index 0000000..5ea60b9 --- /dev/null +++ b/ShortcutUtil/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShortcutUtil.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs new file mode 100755 index 0000000..fbb1aee --- /dev/null +++ b/ShortcutUtil/MainForm.Designer.cs @@ -0,0 +1,90 @@ +namespace ShortcutUtil +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.entryListBox = new System.Windows.Forms.ListBox(); + this.createButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(169, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select default shortcut"; + // + // entryListBox + // + this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.entryListBox.FormattingEnabled = true; + this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Name = "entryListBox"; + this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.TabIndex = 1; + this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); + this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); + // + // createButton + // + this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Name = "createButton"; + this.createButton.Size = new System.Drawing.Size(144, 40); + this.createButton.TabIndex = 2; + this.createButton.Text = "Create Shortcut"; + this.createButton.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AcceptButton = this.createButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 444); + this.Controls.Add(this.createButton); + this.Controls.Add(this.entryListBox); + this.Controls.Add(this.label1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Shown += new System.EventHandler(this.MainForm_Shown); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox entryListBox; + private System.Windows.Forms.Button createButton; + } +} + diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs new file mode 100755 index 0000000..cb5990a --- /dev/null +++ b/ShortcutUtil/MainForm.cs @@ -0,0 +1,132 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class MainForm : Form + { + private EntryList entryList; + + private Font defaultFont; + private Font nameFont; + private Brush fontBrush; + + private bool shown = false; + private Size listSizeOffset; + private Point buttonOffset; + + public MainForm(EntryList entryList) + { + InitializeComponent(); + + defaultFont = label1.Font; + nameFont = new Font(defaultFont, FontStyle.Bold); + fontBrush = new SolidBrush(label1.ForeColor); + + this.entryList = entryList; + + entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + } + + private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); + private Icon GetIcon(string file, int index, Size preferred) + { + Tuple key = new Tuple(file, index, preferred); + + + + if (!iconsByFileIndex.ContainsKey(key)) + { + Icon icon = null; + + try + { + icon = new Icon(file, preferred); + + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } catch (Exception) { } + + try + { + icon = IconExtractor.Extract(file, index, true); + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } + catch (Exception) { } + + MessageBox.Show("Couldn't load icon " + index + " from " + file); + return null; + } + + return iconsByFileIndex[key]; + } + + private static readonly Size IconSize = new Size(64, 64); + private static readonly Size ItemPadding = new Size(6, 6); + + private void entryListBox_DrawItem(object sender, DrawItemEventArgs e) + { + e.DrawBackground(); + e.DrawFocusRectangle(); + + if (e.Index >= 0 && e.Index < entryList.Entries.Count) + { + Rectangle iconBounds = new Rectangle(Point.Add(e.Bounds.Location, ItemPadding), IconSize); + + Size textSize = new Size(0, nameFont.Height + 2); + + Entry entry = entryList.Entries[e.Index]; + e.Graphics.DrawIcon(GetIcon(entry.Icon, entry.IconIndex, IconSize), iconBounds); + + PointF textLocation = PointF.Add(e.Bounds.Location, new Size(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width)); + + e.Graphics.DrawString(e.Index + ": " + entry.Name, nameFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Target, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Description, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + } + } + + private void entryListBox_MeasureItem(object sender, MeasureItemEventArgs e) + { + e.ItemHeight = Size.Add(IconSize, new Size(0, ItemPadding.Height * 2)).Height; + } + + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (shown) + { + entryListBox.Size = Size.Subtract(Size, listSizeOffset); + createButton.Location = Point.Add(buttonOffset, entryListBox.Size); + } + } + + private void MainForm_Shown(object sender, EventArgs e) + { + listSizeOffset = Size.Subtract(Size, entryListBox.Size); + buttonOffset = Point.Subtract(createButton.Location, entryListBox.Size); + + shown = true; + } + } +} diff --git a/ShortcutUtil/MainForm.resx b/ShortcutUtil/MainForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs new file mode 100755 index 0000000..3a962d4 --- /dev/null +++ b/ShortcutUtil/Program.cs @@ -0,0 +1,52 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + string[] args = Environment.GetCommandLineArgs(); + + if (args.Length < 2) + { + MessageBox.Show("Drag a shortcuts.json onto this executable"); + return; + } + + EntryList entryList = null; + try + { + entryList = EntryList.FromFile(args[1]); + } + catch (Exception e) + { + MessageBox.Show("Couldn't load settings file " + args[1] + "\n" + e); + return; + } + + if (entryList.Entries.Count == 0) + { + MessageBox.Show("No shorcuts in that settings file!"); + return; + } + + Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm(entryList)); + } + } +} diff --git a/ShortcutUtil/Properties/AssemblyInfo.cs b/ShortcutUtil/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..e1dc184 --- /dev/null +++ b/ShortcutUtil/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ShortcutUtil")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ShortcutUtil")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("91bac03d-bbbb-403c-a8b0-2f70497f39ba")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ShortcutUtil/Properties/Resources.Designer.cs b/ShortcutUtil/Properties/Resources.Designer.cs new file mode 100755 index 0000000..52776c1 --- /dev/null +++ b/ShortcutUtil/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShortcutUtil.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShortcutUtil.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/ShortcutUtil/Properties/Resources.resx b/ShortcutUtil/Properties/Resources.resx new file mode 100755 index 0000000..ffecec8 --- /dev/null +++ b/ShortcutUtil/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Properties/Settings.Designer.cs b/ShortcutUtil/Properties/Settings.Designer.cs new file mode 100755 index 0000000..5ea60b9 --- /dev/null +++ b/ShortcutUtil/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShortcutUtil.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/ShortcutUtil/Properties/Settings.settings b/ShortcutUtil/Properties/Settings.settings new file mode 100755 index 0000000..abf36c5 --- /dev/null +++ b/ShortcutUtil/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs new file mode 100755 index 0000000..fbb1aee --- /dev/null +++ b/ShortcutUtil/MainForm.Designer.cs @@ -0,0 +1,90 @@ +namespace ShortcutUtil +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.entryListBox = new System.Windows.Forms.ListBox(); + this.createButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(169, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select default shortcut"; + // + // entryListBox + // + this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.entryListBox.FormattingEnabled = true; + this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Name = "entryListBox"; + this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.TabIndex = 1; + this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); + this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); + // + // createButton + // + this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Name = "createButton"; + this.createButton.Size = new System.Drawing.Size(144, 40); + this.createButton.TabIndex = 2; + this.createButton.Text = "Create Shortcut"; + this.createButton.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AcceptButton = this.createButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 444); + this.Controls.Add(this.createButton); + this.Controls.Add(this.entryListBox); + this.Controls.Add(this.label1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Shown += new System.EventHandler(this.MainForm_Shown); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox entryListBox; + private System.Windows.Forms.Button createButton; + } +} + diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs new file mode 100755 index 0000000..cb5990a --- /dev/null +++ b/ShortcutUtil/MainForm.cs @@ -0,0 +1,132 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class MainForm : Form + { + private EntryList entryList; + + private Font defaultFont; + private Font nameFont; + private Brush fontBrush; + + private bool shown = false; + private Size listSizeOffset; + private Point buttonOffset; + + public MainForm(EntryList entryList) + { + InitializeComponent(); + + defaultFont = label1.Font; + nameFont = new Font(defaultFont, FontStyle.Bold); + fontBrush = new SolidBrush(label1.ForeColor); + + this.entryList = entryList; + + entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + } + + private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); + private Icon GetIcon(string file, int index, Size preferred) + { + Tuple key = new Tuple(file, index, preferred); + + + + if (!iconsByFileIndex.ContainsKey(key)) + { + Icon icon = null; + + try + { + icon = new Icon(file, preferred); + + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } catch (Exception) { } + + try + { + icon = IconExtractor.Extract(file, index, true); + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } + catch (Exception) { } + + MessageBox.Show("Couldn't load icon " + index + " from " + file); + return null; + } + + return iconsByFileIndex[key]; + } + + private static readonly Size IconSize = new Size(64, 64); + private static readonly Size ItemPadding = new Size(6, 6); + + private void entryListBox_DrawItem(object sender, DrawItemEventArgs e) + { + e.DrawBackground(); + e.DrawFocusRectangle(); + + if (e.Index >= 0 && e.Index < entryList.Entries.Count) + { + Rectangle iconBounds = new Rectangle(Point.Add(e.Bounds.Location, ItemPadding), IconSize); + + Size textSize = new Size(0, nameFont.Height + 2); + + Entry entry = entryList.Entries[e.Index]; + e.Graphics.DrawIcon(GetIcon(entry.Icon, entry.IconIndex, IconSize), iconBounds); + + PointF textLocation = PointF.Add(e.Bounds.Location, new Size(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width)); + + e.Graphics.DrawString(e.Index + ": " + entry.Name, nameFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Target, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Description, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + } + } + + private void entryListBox_MeasureItem(object sender, MeasureItemEventArgs e) + { + e.ItemHeight = Size.Add(IconSize, new Size(0, ItemPadding.Height * 2)).Height; + } + + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (shown) + { + entryListBox.Size = Size.Subtract(Size, listSizeOffset); + createButton.Location = Point.Add(buttonOffset, entryListBox.Size); + } + } + + private void MainForm_Shown(object sender, EventArgs e) + { + listSizeOffset = Size.Subtract(Size, entryListBox.Size); + buttonOffset = Point.Subtract(createButton.Location, entryListBox.Size); + + shown = true; + } + } +} diff --git a/ShortcutUtil/MainForm.resx b/ShortcutUtil/MainForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs new file mode 100755 index 0000000..3a962d4 --- /dev/null +++ b/ShortcutUtil/Program.cs @@ -0,0 +1,52 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + string[] args = Environment.GetCommandLineArgs(); + + if (args.Length < 2) + { + MessageBox.Show("Drag a shortcuts.json onto this executable"); + return; + } + + EntryList entryList = null; + try + { + entryList = EntryList.FromFile(args[1]); + } + catch (Exception e) + { + MessageBox.Show("Couldn't load settings file " + args[1] + "\n" + e); + return; + } + + if (entryList.Entries.Count == 0) + { + MessageBox.Show("No shorcuts in that settings file!"); + return; + } + + Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm(entryList)); + } + } +} diff --git a/ShortcutUtil/Properties/AssemblyInfo.cs b/ShortcutUtil/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..e1dc184 --- /dev/null +++ b/ShortcutUtil/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ShortcutUtil")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ShortcutUtil")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("91bac03d-bbbb-403c-a8b0-2f70497f39ba")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ShortcutUtil/Properties/Resources.Designer.cs b/ShortcutUtil/Properties/Resources.Designer.cs new file mode 100755 index 0000000..52776c1 --- /dev/null +++ b/ShortcutUtil/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShortcutUtil.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShortcutUtil.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/ShortcutUtil/Properties/Resources.resx b/ShortcutUtil/Properties/Resources.resx new file mode 100755 index 0000000..ffecec8 --- /dev/null +++ b/ShortcutUtil/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Properties/Settings.Designer.cs b/ShortcutUtil/Properties/Settings.Designer.cs new file mode 100755 index 0000000..5ea60b9 --- /dev/null +++ b/ShortcutUtil/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShortcutUtil.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/ShortcutUtil/Properties/Settings.settings b/ShortcutUtil/Properties/Settings.settings new file mode 100755 index 0000000..abf36c5 --- /dev/null +++ b/ShortcutUtil/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ShortcutUtil/ShortcutUtil.csproj b/ShortcutUtil/ShortcutUtil.csproj new file mode 100755 index 0000000..a9c0bce --- /dev/null +++ b/ShortcutUtil/ShortcutUtil.csproj @@ -0,0 +1,116 @@ + + + + + Debug + AnyCPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA} + WinExe + ShortcutUtil + ShortcutUtil + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Text.Encodings.Web.4.7.1\lib\net461\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.4.7.2\lib\net461\System.Text.Json.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + + + + + + + + + + + + + EntryList.cs + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/EntryList.cs b/EntryList.cs new file mode 100755 index 0000000..dd43a65 --- /dev/null +++ b/EntryList.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Entries +{ + public class Entry + { + public string Target { get; set; } + public string Icon { get; set; } + public int IconIndex { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public class EntryList + { + public List Entries; + + public static EntryList FromString(string contents) + { + Entry[] entries = (Entry[])JsonSerializer.Deserialize(contents, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + return new EntryList { Entries = new List(entries) }; + } + + public static EntryList FromFile(string path) + { + string contents = ""; + using (FileStream input = File.OpenRead(path)) + { + contents = new StreamReader(input).ReadToEnd(); + } + return FromString(contents); + } + + public override string ToString() + { + return JsonSerializer.Serialize(Entries.ToArray(), typeof(Entry[]), new JsonSerializerOptions() { WriteIndented = true }); + } + + public void WriteToFile(string path) + { + using (FileStream output = File.Create(path)) + { + new StreamWriter(output).Write(ToString()); + } + } + } +} diff --git a/JumpListUtil.sln b/JumpListUtil.sln index 4219963..165a98a 100755 --- a/JumpListUtil.sln +++ b/JumpListUtil.sln @@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SetLnkApp", "SetLnkApp\SetLnkApp.csproj", "{443B8959-7F3D-4199-838C-7A805427CE42}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShortcutUtil", "ShortcutUtil\ShortcutUtil.csproj", "{91BAC03D-BBBB-403C-A8B0-2F70497F39BA}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ {443B8959-7F3D-4199-838C-7A805427CE42}.Debug|Any CPU.Build.0 = Debug|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.ActiveCfg = Release|Any CPU {443B8959-7F3D-4199-838C-7A805427CE42}.Release|Any CPU.Build.0 = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JumpListUtil/JumpListUtil.csproj b/JumpListUtil/JumpListUtil.csproj index 935dc6f..052af6c 100755 --- a/JumpListUtil/JumpListUtil.csproj +++ b/JumpListUtil/JumpListUtil.csproj @@ -12,6 +12,21 @@ 512 true true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true AnyCPU @@ -75,6 +90,9 @@ + + EntryList.cs + ShellLink.cs @@ -104,5 +122,17 @@ + + + False + Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + \ No newline at end of file diff --git a/JumpListUtil/Program.cs b/JumpListUtil/Program.cs index a13d723..6b8192c 100755 --- a/JumpListUtil/Program.cs +++ b/JumpListUtil/Program.cs @@ -1,4 +1,5 @@ -using System; +using Entries; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -10,14 +11,7 @@ namespace JumpListUtil { - public class Entry - { - public string Target { get; set; } - public string Icon { get; set; } - public int IconIndex { get; set; } - public string Name { get; set; } - public string Description { get; set; } - } + static class Program { [DllImport("shell32.dll", SetLastError = true)] @@ -107,27 +101,20 @@ List jumpItems = new List(); - Entry[] entries = null; + EntryList entryList = null; try { - string shortcutJson = ""; - using (FileStream input = File.OpenRead(shortcutsFile)) - { - shortcutJson = new StreamReader(input).ReadToEnd(); - } - - - entries = (Entry[])JsonSerializer.Deserialize(shortcutJson, typeof(Entry[]), new JsonSerializerOptions() { PropertyNameCaseInsensitive = true, ReadCommentHandling = JsonCommentHandling.Skip, AllowTrailingCommas = true }); + entryList = EntryList.FromFile(shortcutsFile); } catch (Exception e) { MessageBox.Show("Failed to load shortcut entries: " + e); } - if (entries != null) + if (entryList != null) { - foreach (Entry entry in entries) + foreach (Entry entry in entryList.Entries) { JumpTask task = new JumpTask(); task.ApplicationPath = entry.Target; @@ -154,9 +141,9 @@ if (!onlyRefreshJumpList) { - if (startIndex >= 0 && startIndex < entries.Length) + if (startIndex >= 0 && startIndex < entryList.Entries.Count) { - Entry start = entries[startIndex]; + Entry start = entryList.Entries[startIndex]; Process p = Process.Start(new ProcessStartInfo { FileName = start.Target, @@ -165,7 +152,7 @@ } else { - MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entries.Length + " entries)"); + MessageBox.Show("Shortcut index " + startIndex + " is outside the range of valid entries (" + entryList.Entries.Count + " entries)"); } } } diff --git a/ShortcutUtil/App.config b/ShortcutUtil/App.config new file mode 100755 index 0000000..de2fc4c --- /dev/null +++ b/ShortcutUtil/App.config @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/IconExtractor.cs b/ShortcutUtil/IconExtractor.cs new file mode 100755 index 0000000..31d4eb3 --- /dev/null +++ b/ShortcutUtil/IconExtractor.cs @@ -0,0 +1,34 @@ +using System; +using System.Drawing; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace ShortcutUtil +{ + public class IconExtractor + { + + public static Icon Extract(string file, int number, bool largeIcon) + { + IntPtr large; + IntPtr small; + ExtractIconEx(file, number, out large, out small, 1); + try + { + return Icon.FromHandle(largeIcon ? large : small); + } + catch + { + return null; + } + + } + + [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] + private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); + + } +} \ No newline at end of file diff --git a/ShortcutUtil/MainForm.Designer.cs b/ShortcutUtil/MainForm.Designer.cs new file mode 100755 index 0000000..fbb1aee --- /dev/null +++ b/ShortcutUtil/MainForm.Designer.cs @@ -0,0 +1,90 @@ +namespace ShortcutUtil +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.entryListBox = new System.Windows.Forms.ListBox(); + this.createButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(169, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Select default shortcut"; + // + // entryListBox + // + this.entryListBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; + this.entryListBox.FormattingEnabled = true; + this.entryListBox.Location = new System.Drawing.Point(17, 37); + this.entryListBox.Name = "entryListBox"; + this.entryListBox.Size = new System.Drawing.Size(771, 355); + this.entryListBox.TabIndex = 1; + this.entryListBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.entryListBox_DrawItem); + this.entryListBox.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.entryListBox_MeasureItem); + // + // createButton + // + this.createButton.Location = new System.Drawing.Point(644, 398); + this.createButton.Name = "createButton"; + this.createButton.Size = new System.Drawing.Size(144, 40); + this.createButton.TabIndex = 2; + this.createButton.Text = "Create Shortcut"; + this.createButton.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AcceptButton = this.createButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 444); + this.Controls.Add(this.createButton); + this.Controls.Add(this.entryListBox); + this.Controls.Add(this.label1); + this.Name = "MainForm"; + this.Text = "Form1"; + this.Shown += new System.EventHandler(this.MainForm_Shown); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ListBox entryListBox; + private System.Windows.Forms.Button createButton; + } +} + diff --git a/ShortcutUtil/MainForm.cs b/ShortcutUtil/MainForm.cs new file mode 100755 index 0000000..cb5990a --- /dev/null +++ b/ShortcutUtil/MainForm.cs @@ -0,0 +1,132 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + public partial class MainForm : Form + { + private EntryList entryList; + + private Font defaultFont; + private Font nameFont; + private Brush fontBrush; + + private bool shown = false; + private Size listSizeOffset; + private Point buttonOffset; + + public MainForm(EntryList entryList) + { + InitializeComponent(); + + defaultFont = label1.Font; + nameFont = new Font(defaultFont, FontStyle.Bold); + fontBrush = new SolidBrush(label1.ForeColor); + + this.entryList = entryList; + + entryListBox.Items.AddRange(this.entryList.Entries.ToArray()); + } + + private Dictionary, Icon> iconsByFileIndex = new Dictionary, Icon>(); + private Icon GetIcon(string file, int index, Size preferred) + { + Tuple key = new Tuple(file, index, preferred); + + + + if (!iconsByFileIndex.ContainsKey(key)) + { + Icon icon = null; + + try + { + icon = new Icon(file, preferred); + + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } catch (Exception) { } + + try + { + icon = IconExtractor.Extract(file, index, true); + if (icon != null) + { + iconsByFileIndex.Add(key, icon); + return icon; + } + } + catch (Exception) { } + + MessageBox.Show("Couldn't load icon " + index + " from " + file); + return null; + } + + return iconsByFileIndex[key]; + } + + private static readonly Size IconSize = new Size(64, 64); + private static readonly Size ItemPadding = new Size(6, 6); + + private void entryListBox_DrawItem(object sender, DrawItemEventArgs e) + { + e.DrawBackground(); + e.DrawFocusRectangle(); + + if (e.Index >= 0 && e.Index < entryList.Entries.Count) + { + Rectangle iconBounds = new Rectangle(Point.Add(e.Bounds.Location, ItemPadding), IconSize); + + Size textSize = new Size(0, nameFont.Height + 2); + + Entry entry = entryList.Entries[e.Index]; + e.Graphics.DrawIcon(GetIcon(entry.Icon, entry.IconIndex, IconSize), iconBounds); + + PointF textLocation = PointF.Add(e.Bounds.Location, new Size(IconSize.Width + ItemPadding.Width * 2, ItemPadding.Width)); + + e.Graphics.DrawString(e.Index + ": " + entry.Name, nameFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Target, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + + e.Graphics.DrawString(entry.Description, defaultFont, fontBrush, textLocation); + textLocation = PointF.Add(textLocation, textSize); + } + } + + private void entryListBox_MeasureItem(object sender, MeasureItemEventArgs e) + { + e.ItemHeight = Size.Add(IconSize, new Size(0, ItemPadding.Height * 2)).Height; + } + + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (shown) + { + entryListBox.Size = Size.Subtract(Size, listSizeOffset); + createButton.Location = Point.Add(buttonOffset, entryListBox.Size); + } + } + + private void MainForm_Shown(object sender, EventArgs e) + { + listSizeOffset = Size.Subtract(Size, entryListBox.Size); + buttonOffset = Point.Subtract(createButton.Location, entryListBox.Size); + + shown = true; + } + } +} diff --git a/ShortcutUtil/MainForm.resx b/ShortcutUtil/MainForm.resx new file mode 100755 index 0000000..29dcb1b --- /dev/null +++ b/ShortcutUtil/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Program.cs b/ShortcutUtil/Program.cs new file mode 100755 index 0000000..3a962d4 --- /dev/null +++ b/ShortcutUtil/Program.cs @@ -0,0 +1,52 @@ +using Entries; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ShortcutUtil +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + string[] args = Environment.GetCommandLineArgs(); + + if (args.Length < 2) + { + MessageBox.Show("Drag a shortcuts.json onto this executable"); + return; + } + + EntryList entryList = null; + try + { + entryList = EntryList.FromFile(args[1]); + } + catch (Exception e) + { + MessageBox.Show("Couldn't load settings file " + args[1] + "\n" + e); + return; + } + + if (entryList.Entries.Count == 0) + { + MessageBox.Show("No shorcuts in that settings file!"); + return; + } + + Environment.CurrentDirectory = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, args[1])); + + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm(entryList)); + } + } +} diff --git a/ShortcutUtil/Properties/AssemblyInfo.cs b/ShortcutUtil/Properties/AssemblyInfo.cs new file mode 100755 index 0000000..e1dc184 --- /dev/null +++ b/ShortcutUtil/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ShortcutUtil")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ShortcutUtil")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("91bac03d-bbbb-403c-a8b0-2f70497f39ba")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ShortcutUtil/Properties/Resources.Designer.cs b/ShortcutUtil/Properties/Resources.Designer.cs new file mode 100755 index 0000000..52776c1 --- /dev/null +++ b/ShortcutUtil/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShortcutUtil.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ShortcutUtil.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/ShortcutUtil/Properties/Resources.resx b/ShortcutUtil/Properties/Resources.resx new file mode 100755 index 0000000..ffecec8 --- /dev/null +++ b/ShortcutUtil/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ShortcutUtil/Properties/Settings.Designer.cs b/ShortcutUtil/Properties/Settings.Designer.cs new file mode 100755 index 0000000..5ea60b9 --- /dev/null +++ b/ShortcutUtil/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ShortcutUtil.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/ShortcutUtil/Properties/Settings.settings b/ShortcutUtil/Properties/Settings.settings new file mode 100755 index 0000000..abf36c5 --- /dev/null +++ b/ShortcutUtil/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/ShortcutUtil/ShortcutUtil.csproj b/ShortcutUtil/ShortcutUtil.csproj new file mode 100755 index 0000000..a9c0bce --- /dev/null +++ b/ShortcutUtil/ShortcutUtil.csproj @@ -0,0 +1,116 @@ + + + + + Debug + AnyCPU + {91BAC03D-BBBB-403C-A8B0-2F70497F39BA} + WinExe + ShortcutUtil + ShortcutUtil + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Text.Encodings.Web.4.7.1\lib\net461\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.4.7.2\lib\net461\System.Text.Json.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + + + + + + + + + + + + + EntryList.cs + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/ShortcutUtil/packages.config b/ShortcutUtil/packages.config new file mode 100755 index 0000000..abb0b89 --- /dev/null +++ b/ShortcutUtil/packages.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file