Skip to content

Commit f755589

Browse files
Initial Commit
1 parent 35d7fc9 commit f755589

File tree

285 files changed

+1907
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+1907
-0
lines changed

Src/MDT-InstallDiscord.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35521.163 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MDT-InstallDiscord", "MDT-InstallDiscord\MDT-InstallDiscord.csproj", "{F62D304C-3F69-4810-8162-BBD6408F9319}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{F62D304C-3F69-4810-8162-BBD6408F9319}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{F62D304C-3F69-4810-8162-BBD6408F9319}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{F62D304C-3F69-4810-8162-BBD6408F9319}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{F62D304C-3F69-4810-8162-BBD6408F9319}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>MDT_InstallDiscord</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
<!-- Enable Single-File Publishing -->
10+
<PublishSingleFile>true</PublishSingleFile>
11+
<SelfContained>true</SelfContained>
12+
<!-- Include native libraries -->
13+
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
14+
<!-- Reduce file size by trimming -->
15+
<PublishTrimmed>true</PublishTrimmed>
16+
</PropertyGroup>
17+
18+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<_LastSelectedProfileId>C:\Users\HueyJerhynS-CEOSSCS\source\repos\MDT-InstallDiscord\MDT-InstallDiscord\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
5+
</PropertyGroup>
6+
</Project>

Src/MDT-InstallDiscord/Program.cs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using System;
2+
using System.IO;
3+
using System.Diagnostics;
4+
using Microsoft.Win32;
5+
6+
namespace MDT_InstallDiscord
7+
{
8+
internal class Program
9+
{
10+
static int Main(string[] args)
11+
{
12+
const string appName = "CheckAndInstallDiscord";
13+
string networkSharePath = @"\\SSCSMS-BVVRND2\SSCS-DSOShare\DeploymentShare$\Applications\Discord - Discord\MDT-InstallDiscord.exe";
14+
string localPublicPath = @"C:\Users\Public\MDT-InstallDiscord.exe";
15+
string discordFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "discord");
16+
string tempInstallerPath = Path.Combine(Path.GetTempPath(), "DiscordSetup.exe");
17+
string discordDownloadUrl = "https://discord.com/api/downloads/distributions/app/installers/latest?channel=stable&platform=win&arch=x64";
18+
19+
try
20+
{
21+
// /install: Copy executable and configure system
22+
if (args.Length > 0 && args[0].Equals("/install", StringComparison.OrdinalIgnoreCase))
23+
{
24+
Console.WriteLine("Starting /install process...");
25+
26+
// Step 1: Copy the executable to the public folder
27+
if (!File.Exists(localPublicPath))
28+
{
29+
Console.WriteLine($"Copying from network share: {networkSharePath} to {localPublicPath}");
30+
File.Copy(networkSharePath, localPublicPath, true);
31+
Console.WriteLine("Executable copied to public folder successfully.");
32+
}
33+
else
34+
{
35+
Console.WriteLine("Executable already exists in the public folder. Skipping copy.");
36+
}
37+
38+
// Step 2: Configure the system to run at login with /check
39+
Console.WriteLine("Configuring the system to check for Discord at login...");
40+
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true))
41+
{
42+
if (key != null)
43+
{
44+
key.SetValue(appName, $"\"{localPublicPath}\" /check");
45+
Console.WriteLine("System configured successfully.");
46+
}
47+
else
48+
{
49+
Console.WriteLine("Failed to access the registry. Please run as administrator.");
50+
return 1; // General failure
51+
}
52+
}
53+
54+
return 0; // Success
55+
}
56+
57+
// /check: Run at login to install Discord if not already installed
58+
if (args.Length > 0 && args[0].Equals("/check", StringComparison.OrdinalIgnoreCase))
59+
{
60+
Console.WriteLine($"Checking if Discord is installed for user: {Environment.UserName}...");
61+
if (Directory.Exists(discordFolder))
62+
{
63+
Console.WriteLine("Discord is already installed. Exiting...");
64+
return 2; // Discord already installed
65+
}
66+
67+
Console.WriteLine("Discord is not installed. Downloading the latest installer...");
68+
69+
// Download the latest Discord installer
70+
using (var client = new System.Net.WebClient())
71+
{
72+
client.DownloadFile(discordDownloadUrl, tempInstallerPath);
73+
}
74+
Console.WriteLine($"Discord installer downloaded to: {tempInstallerPath}");
75+
76+
// Run the installer silently
77+
Console.WriteLine("Running the Discord installer...");
78+
Process installerProcess = Process.Start(new ProcessStartInfo
79+
{
80+
FileName = tempInstallerPath,
81+
Arguments = "/S",
82+
UseShellExecute = true,
83+
CreateNoWindow = true
84+
});
85+
installerProcess.WaitForExit();
86+
87+
if (installerProcess.ExitCode != 0)
88+
{
89+
Console.WriteLine("Discord installer encountered an error.");
90+
return 4; // Installer error
91+
}
92+
93+
Console.WriteLine("Discord installation completed successfully.");
94+
return 0; // Success
95+
}
96+
97+
// Invalid argument handling
98+
Console.WriteLine("Invalid or missing argument. Use /install or /check.");
99+
return 100; // Invalid argument
100+
}
101+
catch (Exception ex)
102+
{
103+
Console.WriteLine($"An unexpected error occurred: {ex.Message}");
104+
return 1; // General failure
105+
}
106+
finally
107+
{
108+
// Cleanup: Delete the installer file if it exists
109+
if (File.Exists(tempInstallerPath))
110+
{
111+
File.Delete(tempInstallerPath);
112+
Console.WriteLine("Temporary installer file cleaned up.");
113+
}
114+
}
115+
}
116+
}
117+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project>
6+
<PropertyGroup>
7+
<Configuration>Release</Configuration>
8+
<Platform>Any CPU</Platform>
9+
<PublishDir>bin\Release\net8.0\win-x64\publish\</PublishDir>
10+
<PublishProtocol>FileSystem</PublishProtocol>
11+
<_TargetId>Folder</_TargetId>
12+
</PropertyGroup>
13+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project>
6+
<PropertyGroup>
7+
<History>True|2024-12-07T06:26:01.1689369Z||;True|2024-12-07T06:47:52.3333461+01:00||;True|2024-12-07T06:45:51.6973444+01:00||;</History>
8+
<LastFailureDetails />
9+
</PropertyGroup>
10+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"runtimeTarget": {
3+
"name": ".NETCoreApp,Version=v8.0",
4+
"signature": ""
5+
},
6+
"compilationOptions": {},
7+
"targets": {
8+
".NETCoreApp,Version=v8.0": {
9+
"MDT-InstallDiscord/1.0.0": {
10+
"runtime": {
11+
"MDT-InstallDiscord.dll": {}
12+
}
13+
}
14+
}
15+
},
16+
"libraries": {
17+
"MDT-InstallDiscord/1.0.0": {
18+
"type": "project",
19+
"serviceable": false,
20+
"sha512": ""
21+
}
22+
}
23+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"runtimeOptions": {
3+
"tfm": "net8.0",
4+
"framework": {
5+
"name": "Microsoft.NETCore.App",
6+
"version": "8.0.0"
7+
},
8+
"configProperties": {
9+
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
10+
}
11+
}
12+
}

0 commit comments

Comments
 (0)