diff --git a/DiscordIconChanger.sln b/DiscordIconChanger.sln new file mode 100644 index 0000000..4b4ce00 --- /dev/null +++ b/DiscordIconChanger.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33829.357 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscordIconChanger", "DiscordIconChanger\DiscordIconChanger.csproj", "{6B2F12C8-FC2B-4D97-988D-C2BBDB00B3AF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6B2F12C8-FC2B-4D97-988D-C2BBDB00B3AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B2F12C8-FC2B-4D97-988D-C2BBDB00B3AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B2F12C8-FC2B-4D97-988D-C2BBDB00B3AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B2F12C8-FC2B-4D97-988D-C2BBDB00B3AF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7D6DC67B-41D3-4145-BE06-6B64DE3622CC} + EndGlobalSection +EndGlobal diff --git a/DiscordIconChanger/DIC.cs b/DiscordIconChanger/DIC.cs new file mode 100644 index 0000000..fc774c0 --- /dev/null +++ b/DiscordIconChanger/DIC.cs @@ -0,0 +1,57 @@ +using IWshRuntimeLibrary; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Net.Http.Headers; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +// DIC!!! (DiscordIconChanger) + +namespace DiscordIconChanger +{ + internal class DIC + { + [DllImport("shell32.dll", CharSet = CharSet.Unicode)] + public static extern int SHChangeNotify(int wEventId, int uFlags, IntPtr dwItem1, IntPtr dwItem2); + + public static void Perform(string discordRoot, string discordAppDir, string icoPath) + { + string shortcutPath = "C:\\Users\\" + Environment.UserName + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Discord Inc\\Discord.lnk"; + if(!Directory.Exists("C:\\Users\\" + Environment.UserName + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Discord Inc")) + Directory.CreateDirectory("C:\\Users\\" + Environment.UserName + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Discord Inc"); + string[] appIcoPaths = { discordRoot + "\\app.ico", discordAppDir + "\\app.ico" }; + + Console.WriteLine("Replacing old icon files..."); + foreach (var appIco in appIcoPaths) + { + System.IO.File.Move(appIco, Path.GetDirectoryName(appIco) + "\\old_appIco.ico", true); + System.IO.File.Copy(icoPath, appIco, true); + } + + // Create a Shell object + WshShell shell = new WshShell(); + + // Load the existing shortcut + IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath); + + // Set the new icon path + shortcut.IconLocation = appIcoPaths[0]; + shortcut.TargetPath = discordRoot + "\\Update.exe --processStart Discord.exe"; + + Console.WriteLine("Creating new Shortcut"); + // Save the shortcut + shortcut.Save(); + + Console.WriteLine("Copying Shortcut..."); + System.IO.File.Copy(shortcutPath, "C:\\users\\" + Environment.UserName + "\\desktop\\Discord.lnk", true); + + Console.WriteLine("Notifying Shell about Change"); + // Notify the shell about the change + SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero); + } + } +} \ No newline at end of file diff --git a/DiscordIconChanger/DiscordIconChanger.csproj b/DiscordIconChanger/DiscordIconChanger.csproj new file mode 100644 index 0000000..4294b85 --- /dev/null +++ b/DiscordIconChanger/DiscordIconChanger.csproj @@ -0,0 +1,43 @@ + + + + Exe + net6.0 + enable + enable + app.manifest + + + + + tlbimp + 0 + 1 + f935dc20-1cf0-11d0-adb9-00c04fd58a0b + 0 + false + true + + + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + diff --git a/DiscordIconChanger/Program.cs b/DiscordIconChanger/Program.cs new file mode 100644 index 0000000..612e32a --- /dev/null +++ b/DiscordIconChanger/Program.cs @@ -0,0 +1,50 @@ +using DiscordIconChanger; +using System.Drawing; + +class Prpgram +{ + static void Main(string[] args) + { + Console.WriteLine("DiscordIconChanger by pogrammerX (https://github.com/pogrammerX/discord-icon-changer)"); + + if (args.Length != 1) + { + Console.WriteLine("Syntax Error!"); + Console.WriteLine("Usage:"); + Console.WriteLine("\tdiscordiconchanger "); + Console.WriteLine("Or"); + Console.WriteLine("\tdiscordiconchanger --restore (Restores the default Discord Icon)"); + return; + } + + Console.WriteLine("Locating Discord..."); + string discordRoot = "C:\\Users\\" + Environment.UserName + "\\AppData\\Local\\Discord"; + + string discordAppDir = ""; + foreach (var dir in Directory.GetDirectories(discordRoot)) + { + if (Path.GetFileName(dir).StartsWith("app-")) + discordAppDir = dir; + } + + if(string.IsNullOrWhiteSpace(discordAppDir)) + { + Console.WriteLine("Discord not found!"); + Console.WriteLine("We've searched in " + discordRoot + " but didn't find it, have you installed Discord?"); + return; + } + + if (args[0] == "--restore") + { + File.WriteAllBytes(Environment.CurrentDirectory + "\\normal.ico", DiscordIconChanger.Properties.Resources.normal); + DIC.Perform(discordRoot, discordAppDir, Environment.CurrentDirectory + "\\normal.ico"); + File.Delete(Environment.CurrentDirectory + "\\normal.ico"); + Console.WriteLine("Restored!"); + return; + } + + Console.WriteLine("Changing Icon..."); + DIC.Perform(discordRoot, discordAppDir, args[0]); + Console.WriteLine("Finished!"); + } +} \ No newline at end of file diff --git a/DiscordIconChanger/Properties/Resources.Designer.cs b/DiscordIconChanger/Properties/Resources.Designer.cs new file mode 100644 index 0000000..b511407 --- /dev/null +++ b/DiscordIconChanger/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// 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 DiscordIconChanger.Properties { + using System; + + + /// + /// 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", "17.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 (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DiscordIconChanger.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; + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] normal { + get { + object obj = ResourceManager.GetObject("normal", resourceCulture); + return ((byte[])(obj)); + } + } + } +} diff --git a/DiscordIconChanger/Properties/Resources.resx b/DiscordIconChanger/Properties/Resources.resx new file mode 100644 index 0000000..05d3529 --- /dev/null +++ b/DiscordIconChanger/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + ..\Resources\normal.ico;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DiscordIconChanger/Resources/normal.ico b/DiscordIconChanger/Resources/normal.ico new file mode 100644 index 0000000..5418e0a Binary files /dev/null and b/DiscordIconChanger/Resources/normal.ico differ diff --git a/DiscordIconChanger/app.manifest b/DiscordIconChanger/app.manifest new file mode 100644 index 0000000..6a39c83 --- /dev/null +++ b/DiscordIconChanger/app.manifest @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +