Skip to content

Commit

Permalink
Console Only source
Browse files Browse the repository at this point in the history
  • Loading branch information
pogrammerX authored Sep 28, 2023
1 parent 5099bb3 commit 19058c4
Show file tree
Hide file tree
Showing 8 changed files with 451 additions and 0 deletions.
25 changes: 25 additions & 0 deletions DiscordIconChanger.sln
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions DiscordIconChanger/DIC.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
43 changes: 43 additions & 0 deletions DiscordIconChanger/DiscordIconChanger.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>0</VersionMinor>
<VersionMajor>1</VersionMajor>
<Guid>f935dc20-1cf0-11d0-adb9-00c04fd58a0b</Guid>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
<EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeNet" Version="4.0.2" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
50 changes: 50 additions & 0 deletions DiscordIconChanger/Program.cs
Original file line number Diff line number Diff line change
@@ -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 <path to ico file>");
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!");
}
}
73 changes: 73 additions & 0 deletions DiscordIconChanger/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions DiscordIconChanger/Properties/Resources.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="normal" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\normal.ico;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
Binary file added DiscordIconChanger/Resources/normal.ico
Binary file not shown.
Loading

0 comments on commit 19058c4

Please sign in to comment.