Skip to content

Commit 731a2c4

Browse files
committed
Projektdateien hinzufügen.
1 parent 4052cee commit 731a2c4

4 files changed

Lines changed: 266 additions & 0 deletions

File tree

SteamInstaller.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31025.218
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SteamInstaller", "SteamInstaller\SteamInstaller.csproj", "{E4201D20-D8B2-4E1E-8D5B-21AFA22A0CB4}"
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+
{E4201D20-D8B2-4E1E-8D5B-21AFA22A0CB4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E4201D20-D8B2-4E1E-8D5B-21AFA22A0CB4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E4201D20-D8B2-4E1E-8D5B-21AFA22A0CB4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E4201D20-D8B2-4E1E-8D5B-21AFA22A0CB4}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B8B67121-3781-4A1D-994B-96182A1DD2C2}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.Extensions.Logging;
2+
using System;
3+
using System.IO;
4+
using System.Net;
5+
using System.Net.Http;
6+
using System.Threading.Tasks;
7+
8+
namespace SteamInstaller.Extensions
9+
{
10+
public static class DownloadExtension
11+
{
12+
public static bool DownloadAsync(string requestUri, string filename)
13+
{
14+
if (requestUri == null)
15+
{
16+
throw new ArgumentNullException("requestUri can not be null");
17+
}
18+
19+
try
20+
{
21+
var client = new WebClient();
22+
client.DownloadFile(requestUri, filename);
23+
return true;
24+
}
25+
catch(WebException e)
26+
{
27+
28+
return false;
29+
}
30+
}
31+
}
32+
}

SteamInstaller/Program.cs

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using Microsoft.Extensions.Logging;
3+
using SteamInstaller.Extensions;
4+
using System;
5+
using System.Diagnostics;
6+
using System.IO;
7+
using System.IO.Compression;
8+
using System.Net;
9+
using System.Net.Http;
10+
using System.Reflection;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
14+
namespace SteamInstaller
15+
{
16+
class Program
17+
{
18+
/// <summary>
19+
/// Constants
20+
/// </summary>
21+
private const string STEAM_CMD_URL = "https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip";
22+
private const string FILENAME = "steamcmd.zip";
23+
private const string FOLDERNAME = "SteamCMD";
24+
private const string EXE = "steamcmd.exe";
25+
private static string test = "";
26+
27+
private static ILogger logger;
28+
29+
/// <summary>
30+
/// Constructor of SteamInstaller
31+
/// </summary>
32+
/// <param name="args"></param>
33+
static void Main(string[] args)
34+
{
35+
Console.WriteLine(Environment.NewLine);
36+
WriteColor(@"[$$$$$$$$\ $$\ $$\ $$$$$$\ $$\]", ConsoleColor.DarkGreen);
37+
WriteColor(@"[$$ _____|\__| $$ | $$ __$$\ $$ |]", ConsoleColor.DarkGreen);
38+
WriteColor(@"[$$ | $$\ $$$$$$\ $$$$$$$\ $$$$$$\ $$ / \__| $$$$$$\ $$$$$$$ | $$$$$$\ $$$$$$\]", ConsoleColor.DarkGreen);
39+
WriteColor(@"[$$$$$\ $$ |$$ __$$\ $$ _____|\_$$ _|$$$$$$\ $$ | $$ __$$\ $$ __$$ |$$ __$$\ $$ __$$\]", ConsoleColor.DarkGreen);
40+
WriteColor(@"[$$ __| $$ |$$ | \__|\$$$$$$\ $$ | \______|$$ | $$ / $$ |$$ / $$ |$$$$$$$$ |$$ | \__|]", ConsoleColor.DarkGreen);
41+
WriteColor(@"[$$ | $$ |$$ | \____$$\ $$ |$$\ $$ | $$\ $$ | $$ |$$ | $$ |$$ ____|$$ |]", ConsoleColor.DarkGreen);
42+
WriteColor(@"[$$ | $$ |$$ | $$$$$$$ | \$$$$ | \$$$$$$ |\$$$$$$ |\$$$$$$$ |\$$$$$$$\ $$ |]", ConsoleColor.DarkGreen);
43+
WriteColor(@"[\__| \__|\__| \_______/ \____/ \______/ \______/ \_______| \_______|\__|]", ConsoleColor.DarkGreen);
44+
Console.WriteLine(Environment.NewLine);
45+
46+
WriteColor(@"[//--Informationen------------------------------------------------]", ConsoleColor.DarkGreen);
47+
WriteColor($"[// Title:] {Assembly.GetEntryAssembly().GetName().Name}", ConsoleColor.DarkGreen);
48+
WriteColor($"[// Version:] {Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version}", ConsoleColor.DarkGreen);
49+
WriteColor($"[// Autor:] {Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright}", ConsoleColor.DarkGreen);
50+
51+
52+
var serviceCollection = new ServiceCollection();
53+
ConfigureServices(serviceCollection);
54+
55+
var serviceProvider = serviceCollection.BuildServiceProvider();
56+
logger = serviceProvider.GetService<ILogger<Program>>();
57+
58+
if (DownloadFile())
59+
{
60+
Directory.Delete(FOLDERNAME, true);
61+
62+
logger.LogInformation($"Unzip {FILENAME} to {FOLDERNAME}");
63+
ZipFile.ExtractToDirectory(FILENAME, FOLDERNAME);
64+
65+
logger.LogInformation($"Execute {EXE}");
66+
using (Process compiler = new Process())
67+
{
68+
compiler.StartInfo.FileName = $"{FOLDERNAME}/{EXE}";
69+
compiler.StartInfo.Arguments = "+quit";
70+
compiler.StartInfo.UseShellExecute = false;
71+
compiler.StartInfo.CreateNoWindow = true;
72+
compiler.StartInfo.RedirectStandardOutput = true;
73+
compiler.OutputDataReceived += Compiler_OutputDataReceived;
74+
75+
compiler.Start();
76+
compiler.BeginOutputReadLine();
77+
78+
compiler.WaitForExit();
79+
var bytes = Encoding.ASCII.GetBytes(test);
80+
Console.WriteLine(Encoding.UTF8.GetString(bytes));
81+
82+
logger.LogInformation($"{EXE} finished with code {compiler.ExitCode}");
83+
logger.LogInformation($"{FOLDERNAME} is successful installed!");
84+
85+
compiler.Close();
86+
}
87+
}
88+
89+
logger.LogInformation("HELLO GUYS");
90+
Console.ReadKey();
91+
//_ = DownloadExtension.DownloadAsync(STEAM_CMD_URL, "steamcmd.zip");
92+
//Console.WriteLine("Hello World!");
93+
}
94+
95+
/// <summary>
96+
/// Write some coloring console messages for the user
97+
/// https://stackoverflow.com/questions/2743260/is-it-possible-to-write-to-the-console-in-colour-in-net
98+
/// </summary>
99+
/// <param name="message">Message to write</param>
100+
/// <param name="color">ConsoleColor value of the color</param>
101+
static void WriteColor(string message, ConsoleColor color)
102+
{
103+
var pieces = Regex.Split(message, @"(\[[^\]]*\])");
104+
105+
for (int i = 0; i < pieces.Length; i++)
106+
{
107+
string piece = pieces[i];
108+
109+
if (piece.StartsWith("[") && piece.EndsWith("]"))
110+
{
111+
Console.ForegroundColor = color;
112+
piece = piece.Substring(1, piece.Length - 2);
113+
}
114+
115+
Console.Write(piece);
116+
Console.ResetColor();
117+
}
118+
119+
Console.WriteLine();
120+
}
121+
122+
private async static void Test()
123+
{
124+
125+
126+
127+
128+
129+
//var proc = new Process
130+
//{
131+
// StartInfo = new ProcessStartInfo
132+
// {
133+
// FileName = $"{FOLDERNAME}/{EXE}",
134+
// UseShellExecute = false,
135+
// RedirectStandardOutput = true,
136+
// RedirectStandardInput = true,
137+
138+
// CreateNoWindow = true
139+
// }
140+
//};
141+
142+
//proc.Start();
143+
144+
//while (!proc.StandardOutput.EndOfStream)
145+
//{
146+
// await Task.Delay(5000);
147+
// //proc.Dispose();
148+
//}
149+
//proc.Dispose();
150+
////proc.WaitForExit();
151+
//logger.LogInformation($"{EXE} finished with code {proc.ExitCode}");
152+
//logger.LogInformation($"{FOLDERNAME} is successful installed!");
153+
//proc.Close();
154+
}
155+
156+
private static void Compiler_OutputDataReceived(object sender, DataReceivedEventArgs e)
157+
{
158+
//Console.WriteLine(e.Data);
159+
test += e.Data + Environment.NewLine;
160+
}
161+
162+
private static void ConfigureServices(IServiceCollection services)
163+
{
164+
services.AddLogging(configure => configure.AddConsole());
165+
}
166+
167+
private static bool DownloadFile()
168+
{
169+
logger.LogInformation($"Start download steamcmd from {STEAM_CMD_URL}");
170+
try
171+
{
172+
var client = new WebClient();
173+
client.DownloadFile(STEAM_CMD_URL, FILENAME);
174+
logger.LogInformation("Download complete!");
175+
return true;
176+
}
177+
catch (WebException e)
178+
{
179+
var response = (HttpWebResponse)e.Response;
180+
logger.LogError($"Download failed! Webexception ended with status: {response.StatusCode}");
181+
logger.LogError(e.Message);
182+
return false;
183+
}
184+
}
185+
}
186+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
7+
<Copyright>L. Gmann</Copyright>
8+
<RepositoryUrl>https://github.com/First-Coder/SpawnCodeGenerator</RepositoryUrl>
9+
<PackageLicenseFile>LICENCE.txt</PackageLicenseFile>
10+
<PackageProjectUrl>https://first-coder.de/</PackageProjectUrl>
11+
<Authors>L. Gmann</Authors>
12+
<Company>First Coder</Company>
13+
<AssemblyVersion>1.0.0.0</AssemblyVersion>
14+
<FileVersion>1.0.0.0</FileVersion>
15+
</PropertyGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" />
19+
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
20+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
21+
</ItemGroup>
22+
23+
</Project>

0 commit comments

Comments
 (0)