Skip to content

Commit 5504a50

Browse files
committed
Initial version of the program
0 parents  commit 5504a50

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed

.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Everything is text unless it isn’t
2+
* text=auto
3+
4+
# This is really text
5+
*.cs text
6+
*.xaml text
7+
8+
# This is Windows-specific and should always have CRLF
9+
*.sln text eol=crlf
10+
*.csproj text eol=crlf
11+
*.resx text eol=crlf

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.vs/
2+
*.v12.suo
3+
*.VC.db
4+
*.VC.opendb
5+
*.vcxproj.user
6+
*.csproj.user
7+
8+
bin/
9+
obj/

Program.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using chocolatey;
2+
using chocolatey.infrastructure.logging;
3+
using System;
4+
using System.Diagnostics;
5+
using System.Reflection;
6+
using System.Security.Principal;
7+
8+
namespace install_chocolatey
9+
{
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
// If not running with elevated privileges, try to acquire them
15+
var identity = WindowsIdentity.GetCurrent();
16+
var principal = new WindowsPrincipal(identity);
17+
if (!principal.IsInRole(WindowsBuiltInRole.Administrator))
18+
{
19+
Process p = new Process();
20+
p.StartInfo.FileName = Assembly.GetExecutingAssembly().Location;
21+
p.StartInfo.Verb = "runas"; // elevated privileges
22+
p.StartInfo.UseShellExecute = true;
23+
try
24+
{
25+
p.Start();
26+
return;
27+
}
28+
catch
29+
{
30+
Console.WriteLine("Error: must be run as administrator");
31+
}
32+
}
33+
else
34+
{
35+
// Set this environment variable to a sensible default value, otherwise chocolatey.lib will use the executable location
36+
if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ChocolateyInstall")))
37+
Environment.SetEnvironmentVariable("ChocolateyInstall", @"C:\ProgramData\chocolatey");
38+
39+
var choco = Lets.GetChocolatey();
40+
choco.SetCustomLogging(new NullLog());
41+
42+
choco.Set(conf => conf.CommandName = "upgrade");
43+
choco.RunConsole(new string[] { "-y", "--force", "chocolatey" });
44+
choco.RunConsole(new string[] { "-y", "--force", "chocolatey-gui" });
45+
46+
Console.Write("\n\nSetup was successful. Press any key to quit.\n");
47+
}
48+
49+
Console.ReadKey();
50+
}
51+
}
52+
}

install-chocolatey.csproj

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<ProjectGuid>{E0F8D1D0-B649-476B-860A-3D17D42475F9}</ProjectGuid>
4+
<OutputType>Exe</OutputType>
5+
<RootNamespace>install_chocolatey</RootNamespace>
6+
<TargetFramework>net48</TargetFramework>
7+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
8+
<AssemblyTitle>install-chocolatey</AssemblyTitle>
9+
<Product>install-chocolatey</Product>
10+
<Copyright>Copyright © 2021</Copyright>
11+
<OutputPath>bin\$(Configuration)\</OutputPath>
12+
</PropertyGroup>
13+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14+
<DebugType>full</DebugType>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
17+
<DebugType>pdbonly</DebugType>
18+
</PropertyGroup>
19+
<ItemGroup>
20+
<Reference Include="System.Data.DataSetExtensions" />
21+
<Reference Include="Microsoft.CSharp" />
22+
<Reference Include="System.Net.Http" />
23+
</ItemGroup>
24+
<ItemGroup>
25+
<PackageReference Include="chocolatey.lib" Version="0.11.2" />
26+
<PackageReference Include="GitVersion.MsBuild" Version="5.7.0">
27+
<PrivateAssets>all</PrivateAssets>
28+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
29+
</PackageReference>
30+
<PackageReference Include="log4net" Version="2.0.12" />
31+
</ItemGroup>
32+
</Project>

install-chocolatey.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.31729.503
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "install-chocolatey", "install-chocolatey.csproj", "{E0F8D1D0-B649-476B-860A-3D17D42475F9}"
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+
{E0F8D1D0-B649-476B-860A-3D17D42475F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E0F8D1D0-B649-476B-860A-3D17D42475F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E0F8D1D0-B649-476B-860A-3D17D42475F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E0F8D1D0-B649-476B-860A-3D17D42475F9}.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 = {040DE2E6-CBBE-43EC-88EB-2B64390F9752}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)