Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
dayo05 committed Aug 15, 2021
1 parent c954e68 commit e8541e7
Show file tree
Hide file tree
Showing 18 changed files with 822 additions and 0 deletions.
31 changes: 31 additions & 0 deletions MindustryInstaller.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31515.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MindustryInstaller", "MindustryInstaller\MindustryInstaller.csproj", "{AD73FD7A-F762-463F-9E54-8A8B060DAC2E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MindustryLauncher", "MindustryLauncher\MindustryLauncher.csproj", "{1F881E72-0A19-418B-8622-3B44F4E3D950}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AD73FD7A-F762-463F-9E54-8A8B060DAC2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD73FD7A-F762-463F-9E54-8A8B060DAC2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD73FD7A-F762-463F-9E54-8A8B060DAC2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD73FD7A-F762-463F-9E54-8A8B060DAC2E}.Release|Any CPU.Build.0 = Release|Any CPU
{1F881E72-0A19-418B-8622-3B44F4E3D950}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F881E72-0A19-418B-8622-3B44F4E3D950}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F881E72-0A19-418B-8622-3B44F4E3D950}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F881E72-0A19-418B-8622-3B44F4E3D950}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2A4F7F56-29C6-411C-AB63-D94A2DC81E1B}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions MindustryInstaller/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
9 changes: 9 additions & 0 deletions MindustryInstaller/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="MindustryInstaller.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MindustryInstaller"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions MindustryInstaller/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace MindustryInstaller
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
18 changes: 18 additions & 0 deletions MindustryInstaller/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Window x:Class="MindustryInstaller.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MindustryInstaller"
mc:Ignorable="d"
Title="MainWindow" Height="278.5" Width="422.5">
<Grid>
<CheckBox Name="DownloadJavaCheckbox" Content="Download JAVA" HorizontalAlignment="Center" Margin="46,55,28,0" VerticalAlignment="Top" Width="130" IsChecked="true"/>
<CheckBox Name="UseStableVersionCheckbox" Content="Use stable version" HorizontalAlignment="Center" Margin="46,75,28,0" VerticalAlignment="Top" RenderTransformOrigin="0.343,-0.378" Width="130" Checked="UseStableVersionCheckbox_Checked" IsChecked="true" Unchecked="UseStableVersionCheckbox_Unchecked"/>
<Label Name="VersionLabel" Content="Mindustry version: null" HorizontalAlignment="Center" Margin="37,95,15,0" VerticalAlignment="Top" Width="152"/>
<Button Name="InstallButton" Content="Install" HorizontalAlignment="Center" Margin="63,126,66,0" VerticalAlignment="Top" Width="75" Click="InstallButton_Click"/>
<ScrollViewer Name="logView" Margin="0,151,0,0">
<TextBlock Name="LogTextBlock" HorizontalAlignment="Left" Margin="0,0,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" />
</ScrollViewer>
</Grid>
</Window>
167 changes: 167 additions & 0 deletions MindustryInstaller/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
using System;
using System.IO;
using System.Net;
using System.Windows;
using System.IO.Compression;
using System.Collections.Generic;

using Microsoft.Win32;

using Newtonsoft.Json;
using System.Threading;
using System.Threading.Tasks;

namespace MindustryInstaller
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Directory.CreateDirectory(InstallDir);
Directory.CreateDirectory(TempDir);
}
bool DownloadJAVA = true;
string InstallDir = @"C:\Program Files\Mindustry\";
string TempDir = Path.GetTempPath() + "MindustryInstaller";
bool DownloadStable = true;
string version = null;
int downloadstat = 0;
int tick = 0;
void PrintLog(string log)
{
Invoke(() => LogTextBlock.Text += log + '\n');
Invoke(() => logView.ScrollToBottom());
}

//Gets version of Mindustry
void LoadVersion()
{
Invoke(() => InstallButton.IsEnabled = false);
Invoke(() => UseStableVersionCheckbox.IsEnabled = false);
using (var wc = new WebClient())
{
wc.Headers["User-Agent"] = "ua";
if (DownloadStable)
{
PrintLog("Searching stable version");
version = wc.DownloadString("https://api.github.com/repos/Anuken/Mindustry/releases/latest");
version = JsonConvert.DeserializeObject<Dictionary<string, object>>(version)["tag_name"] as string;
}
else
{
PrintLog("Searching preview version");
version = wc.DownloadString("https://api.github.com/repos/Anuken/Mindustry/releases");
version = JsonConvert.DeserializeObject<List<Dictionary<string, dynamic>>>(version)[0]["tag_name"] as string;
}
PrintLog($"{version} found");
Invoke(() => VersionLabel.Content = "Mindustry version: " + version);
}
Invoke(() => InstallButton.IsEnabled = true);
Invoke(() => UseStableVersionCheckbox.IsEnabled = true);
}
void Invoke(Action a)
=> Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, (ThreadStart)delegate() { a(); });
//Install Mindustry
void Install()
{
Invoke(() => InstallButton.IsEnabled = false);
Invoke(() => DownloadJAVA = DownloadJavaCheckbox.IsChecked.Value);
PrintLog("Download Java: " + (DownloadJAVA ? "true" : "false"));
PrintLog("Download version: " + version);
try
{
Directory.CreateDirectory(InstallDir);
using (var wc = new WebClient())
{
wc.DownloadProgressChanged += WC_DownloadProgressChanged;
wc.DownloadFileCompleted += WC_DownloadFileCompleted;
wc.Headers["User-Agent"] = "MindustryInstaller";
PrintLog("Setup: WebClient");
if (DownloadJAVA)
{
try
{
Directory.Delete(Path.GetTempPath() + @"java", true);
}
catch (DirectoryNotFoundException) { }
downloadstat = 1;
var sync = new object();
lock (sync)
{
wc.DownloadFileAsync(new Uri("https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_windows-x64_bin.zip"), Path.GetTempPath() + "mindustry-java.zip");
Monitor.Wait(sync);
}
PrintLog("Extrecting JAVA Java to " + InstallDir + "java");
ZipFile.ExtractToDirectory(Path.GetTempPath() + "mindustry-java.zip", Path.GetTempPath() + "java");
Directory.Move(Path.GetTempPath() + @"java\jdk-16.0.2", InstallDir + "java");
}
if (File.Exists(InstallDir + "Mindustry.jar"))
File.Delete(InstallDir + "Mindustry.jar");
downloadstat = 2;
var sync2 = new object();
lock (sync2)
{
wc.DownloadFile($"https://github.com/Anuken/Mindustry/releases/download/{version}/Mindustry.jar", InstallDir + "Mindustry.jar");
Monitor.Wait(sync2);
}
}
PrintLog("Cleaning files");
try
{
Directory.Delete(Path.GetTempPath() + @"java", true);
}
catch (DirectoryNotFoundException) { }
try
{
File.Delete(Path.GetTempPath() + "mindustry-java.zip");
}
catch (DirectoryNotFoundException) { }
}
catch (Exception e)
{
_ = MessageBox.Show(e.Message);
}
downloadstat = 0;
Invoke(() => InstallButton.IsEnabled = true);
}

private void WC_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
if (downloadstat == 1)
PrintLog("Java Downloaded");
else if (downloadstat == 2)
PrintLog("Mindustry Downloaded");
Monitor.Pulse(e.UserState);
}

private void WC_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
if (tick++ % 100 == 0)
{
if (downloadstat == 1)
PrintLog($"Downloading JAVA...{e.ProgressPercentage}% ({e.BytesReceived} / {e.TotalBytesToReceive})");
else if (downloadstat == 2)
PrintLog($"Downloading Mindustry...{e.ProgressPercentage}% ({e.BytesReceived} / {e.TotalBytesToReceive})");
}
}

private void InstallButton_Click(object sender, RoutedEventArgs e)
=> new Thread(() => Install()).Start();

private void UseStableVersionCheckbox_Checked(object sender, RoutedEventArgs e)
{
DownloadStable = true;
new Thread(() => LoadVersion()).Start();
}

private void UseStableVersionCheckbox_Unchecked(object sender, RoutedEventArgs e)
{
DownloadStable = false;
new Thread(() => LoadVersion()).Start();
}
}
}
117 changes: 117 additions & 0 deletions MindustryInstaller/MindustryInstaller.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AD73FD7A-F762-463F-9E54-8A8B060DAC2E}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>MindustryInstaller</RootNamespace>
<AssemblyName>MindustryInstaller</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignManifests>false</SignManifests>
</PropertyGroup>
<PropertyGroup>
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<PropertyGroup>
<GenerateManifests>false</GenerateManifests>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\app.manifest" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading

0 comments on commit e8541e7

Please sign in to comment.