Skip to content

Commit 163caa2

Browse files
authored
Added GUI and seperated Functionality
1 parent 00dae86 commit 163caa2

18 files changed

+762
-20
lines changed

DiscordIconChanger.Core/DIC.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using IWshRuntimeLibrary;
2+
using System.Runtime.InteropServices;
3+
4+
namespace DiscordIconChanger.Core
5+
{
6+
public static class DIC
7+
{
8+
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
9+
static extern int SHChangeNotify(int wEventId, int uFlags, IntPtr dwItem1, IntPtr dwItem2);
10+
11+
public static void Perform(string discordRoot, string discordAppDir, string icoPath)
12+
{
13+
string shortcutPath = "C:\\Users\\" + Environment.UserName + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Discord Inc\\Discord.lnk";
14+
if(!Directory.Exists("C:\\Users\\" + Environment.UserName + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Discord Inc"))
15+
Directory.CreateDirectory("C:\\Users\\" + Environment.UserName + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Discord Inc");
16+
string[] appIcoPaths = { discordRoot + "\\app.ico", discordAppDir + "\\app.ico" };
17+
18+
Console.WriteLine("Replacing old icon files...");
19+
foreach (var appIco in appIcoPaths)
20+
{
21+
System.IO.File.Copy(icoPath, appIco, true);
22+
}
23+
24+
// Create a Shell object
25+
WshShell shell = new WshShell();
26+
27+
// Load the existing shortcut
28+
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);
29+
30+
// Set the new icon path
31+
shortcut.IconLocation = appIcoPaths[0];
32+
shortcut.TargetPath = discordRoot + "\\Update.exe --processStart Discord.exe";
33+
34+
Console.WriteLine("Creating new Shortcut");
35+
// Save the shortcut
36+
shortcut.Save();
37+
38+
Console.WriteLine("Copying Shortcut...");
39+
System.IO.File.Copy(shortcutPath, "C:\\users\\" + Environment.UserName + "\\desktop\\Discord.lnk", true);
40+
41+
Console.WriteLine("Notifying Shell about Change");
42+
// Notify the shell about the change
43+
SHChangeNotify(0x08000000, 0x0000, IntPtr.Zero, IntPtr.Zero);
44+
}
45+
46+
public static void Perform(DiscordLocation location, string icoPath)
47+
{
48+
Perform(location.Root, location.App, icoPath);
49+
}
50+
}
51+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<COMReference Include="IWshRuntimeLibrary">
11+
<WrapperTool>tlbimp</WrapperTool>
12+
<VersionMinor>0</VersionMinor>
13+
<VersionMajor>1</VersionMajor>
14+
<Guid>f935dc20-1cf0-11d0-adb9-00c04fd58a0b</Guid>
15+
<Lcid>0</Lcid>
16+
<Isolated>false</Isolated>
17+
<EmbedInteropTypes>true</EmbedInteropTypes>
18+
</COMReference>
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace DiscordIconChanger.Core
8+
{
9+
public struct DiscordLocation
10+
{
11+
public string Root;
12+
public string App;
13+
}
14+
15+
public class DiscordUtil
16+
{
17+
public static DiscordLocation LocateDiscord()
18+
{
19+
Console.WriteLine("Locating Discord...");
20+
string discordRoot = "C:\\Users\\" + Environment.UserName + "\\AppData\\Local\\Discord";
21+
22+
string discordAppDir = "";
23+
foreach (var dir in Directory.GetDirectories(discordRoot))
24+
{
25+
if (Path.GetFileName(dir).StartsWith("app-"))
26+
discordAppDir = dir;
27+
}
28+
29+
if (string.IsNullOrWhiteSpace(discordAppDir) || !Directory.Exists(discordRoot))
30+
{
31+
throw new("Discord not found.");
32+
}
33+
34+
return new DiscordLocation { App = discordAppDir, Root = discordRoot };
35+
}
36+
}
37+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net6.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<UseWindowsForms>true</UseWindowsForms>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\DiscordIconChanger.Core\DiscordIconChanger.Core.csproj" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<Compile Update="Properties\Resources.Designer.cs">
17+
<DesignTime>True</DesignTime>
18+
<AutoGen>True</AutoGen>
19+
<DependentUpon>Resources.resx</DependentUpon>
20+
</Compile>
21+
<Compile Update="Properties\Settings.Designer.cs">
22+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
23+
<AutoGen>True</AutoGen>
24+
<DependentUpon>Settings.settings</DependentUpon>
25+
</Compile>
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<EmbeddedResource Update="Properties\Resources.resx">
30+
<Generator>ResXFileCodeGenerator</Generator>
31+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
32+
</EmbeddedResource>
33+
</ItemGroup>
34+
35+
<ItemGroup>
36+
<None Update="Properties\Settings.settings">
37+
<Generator>SettingsSingleFileGenerator</Generator>
38+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
39+
</None>
40+
</ItemGroup>
41+
42+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Compile Update="Form1.cs">
5+
<SubType>Form</SubType>
6+
</Compile>
7+
</ItemGroup>
8+
</Project>

DiscordIconChanger.GUI/Form1.Designer.cs

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DiscordIconChanger.GUI/Form1.cs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using DiscordIconChanger.Core;
2+
using System.Drawing.Drawing2D;
3+
using System.Text.RegularExpressions;
4+
5+
namespace DiscordIconChanger.GUI
6+
{
7+
public partial class Form1 : Form
8+
{
9+
static int r = 255, g = 0, b = 0;
10+
11+
void doRGB()
12+
{
13+
if (r > 0 && b == 0)
14+
{
15+
r--;
16+
g++;
17+
}
18+
if (g > 0 && r == 0)
19+
{
20+
g--;
21+
b++;
22+
}
23+
if (b > 0 && g == 0)
24+
{
25+
r++;
26+
b--;
27+
}
28+
}
29+
30+
public Form1()
31+
{
32+
Icon = SystemIcons.Application;
33+
InitializeComponent();
34+
DoubleBuffered = true;
35+
System.Windows.Forms.Timer timer = new();
36+
timer.Tick += (o, e) => { Invoke(() => Invalidate()); };
37+
timer.Interval = 1;
38+
timer.Start();
39+
}
40+
41+
private void Form1_Paint(object sender, PaintEventArgs e)
42+
{
43+
e.Graphics.Clear(Color.Black);
44+
45+
var brush = new SolidBrush(Color.FromArgb(100, r, g, b));
46+
e.Graphics.FillRectangle(brush, this.ClientRectangle);
47+
brush.Dispose();
48+
49+
doRGB();
50+
}
51+
52+
private void Form1_Load(object sender, EventArgs e)
53+
{
54+
label1.BackColor = Color.Transparent;
55+
button1.BackColor = Color.Transparent;
56+
button3.BackColor = Color.Transparent;
57+
button1.Cursor = Cursors.No;
58+
button1.Enabled = false;
59+
button3.Cursor = Cursors.No;
60+
button3.Enabled = false;
61+
try
62+
{
63+
DiscordUtil.LocateDiscord();
64+
label1.Text = "Discord Found!";
65+
label1.ForeColor = Color.Lime;
66+
button1.Cursor = Cursors.Default;
67+
button1.Enabled = true;
68+
button3.Cursor = Cursors.Default;
69+
button3.Enabled = true;
70+
}
71+
catch (Exception ex)
72+
{
73+
label1.Text = "Discord not found!";
74+
label1.ForeColor = Color.Red;
75+
}
76+
77+
if (label1.ForeColor == Color.Lime)
78+
{
79+
80+
}
81+
}
82+
83+
private void button3_Click(object sender, EventArgs e)
84+
{
85+
File.WriteAllBytes(Environment.CurrentDirectory + "\\normal.ico", Properties.Resources.normal);
86+
DIC.Perform(DiscordUtil.LocateDiscord(), Environment.CurrentDirectory + "\\normal.ico");
87+
File.Delete(Environment.CurrentDirectory + "\\normal.ico");
88+
MessageBox.Show("Restored!", "Discord Icon Changer", MessageBoxButtons.OK, MessageBoxIcon.Information);
89+
}
90+
91+
private void button1_Click_1(object sender, EventArgs e)
92+
{
93+
OpenFileDialog ofd = new();
94+
ofd.Filter = "Icon Files | *.ico";
95+
ofd.FileName = "";
96+
ofd.Title = "Select Icon";
97+
DialogResult a = ofd.ShowDialog();
98+
if (a != DialogResult.Cancel)
99+
{
100+
if (!File.Exists(ofd.FileName))
101+
{
102+
MessageBox.Show(ofd.FileName + " was not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
103+
return;
104+
}
105+
106+
DIC.Perform(DiscordUtil.LocateDiscord(), ofd.FileName);
107+
MessageBox.Show("Icon Changed!", "Discord Icon Changer", MessageBoxButtons.OK, MessageBoxIcon.Information);
108+
}
109+
}
110+
}
111+
}

0 commit comments

Comments
 (0)