Skip to content

Commit

Permalink
Add autogenerate launch batch
Browse files Browse the repository at this point in the history
Add accept EULA
  • Loading branch information
DarkEyeDragon committed Jun 9, 2019
1 parent 162a284 commit c4c1c59
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 1 deletion.
51 changes: 51 additions & 0 deletions PaperDownloader/Launch/Batch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using PaperDownloader.Servers.Versions;

namespace PaperDownload.Launch
{
class Batch
{
public string Arguments { get; }
public string FileName { get; set; }
public string WorkingDir { get; set; }

public Batch(Project project, string version, string build, string workingDir, string fileName)
{
WorkingDir = workingDir;
FileName = fileName;

Arguments =
$":start\r\necho off\r\ncls\r\njava -Xms3G -Xmx3G -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=100 -XX:+DisableExplicitGC -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50 -XX:G1MaxNewSizePercent=80 -XX:G1MixedGCLiveThresholdPercent=35 -XX:+AlwaysPreTouch -XX:+ParallelRefProcEnabled -jar {project}-{version}_{build}.jar\r\npause\r\ngoto start";
}

public void Create()
{
var path = Path.Combine(WorkingDir, FileName);
try
{
if (File.Exists(path))
{
File.Delete(path);
}

// Create a new file
using (var fs = File.CreateText(path))
{
// Add some text to file
fs.WriteLine(Arguments);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
52 changes: 52 additions & 0 deletions PaperDownloader/Launch/Eula.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PaperDownload.Launch
{
class Eula
{
public string WorkingDir { get; set; }
public string Message { get; }

public Eula(string workingDir, bool accept)
{
WorkingDir = workingDir;

Message =
"#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula)."
+ "\r\n#You also agree that tacos are tasty, and the best food in the world."
+ $"\r\n#{string.Format(CultureInfo.InvariantCulture, "{0:ddd MMM dd HH:mm:ss z yyyy}", DateTime.Now)}"
+ $"\r\neula={accept.ToString().ToLower()}";
}

//EEE MMM dd HH:mm:ss Z yyyy
public void Create()
{
var path = Path.Combine(WorkingDir, "eula.txt");
try
{
if (File.Exists(path))
{
File.Delete(path);
}

// Create a new file
using (var fs = File.CreateText(path))
{
// Add some text to file
fs.WriteLine(Message);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
6 changes: 6 additions & 0 deletions PaperDownloader/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<RowDefinition Height="40" />
<RowDefinition Height="30"/>
<RowDefinition Height="80"/>
<RowDefinition Height="70"/>

</Grid.RowDefinitions>
<Grid Column="0" Row="2">
Expand Down Expand Up @@ -63,6 +64,11 @@
<ProgressBar Name="ProgressBarDownload"/>
</Button>
<Button Margin="3,8" Grid.Row="1" Grid.Column="1" Content="Browse..." Name="ButtonBrowse" Click="ButtonBrowse_Click"/>
<StackPanel Grid.Column="0" Grid.Row="4" Margin="3">
<CheckBox Margin="0,4" Name="CheckBoxGenerateBatch" IsChecked="False" Content="Create optimized launch.bat" Checked="CheckBoxIsLatest_OnChecked"/>
<CheckBox Margin="0,4" Name="CheckBoxGenerateEula" IsChecked="False" Content="Accept EULA" Checked="CheckBoxIsLatest_OnChecked"/>
</StackPanel>

</Grid>
</Grid>
</Window>
13 changes: 13 additions & 0 deletions PaperDownloader/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.WindowsAPICodePack.Dialogs;
using PaperDownload.Launch;
using PaperDownloader.Servers.Versions;

namespace PaperDownloader
Expand Down Expand Up @@ -81,6 +82,18 @@ private void ButtonDownloadJar_OnClick(object sender, RoutedEventArgs e)
{
MessageBox.Show("Please provide a valid path", "Invalid Path!",
MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

if (CheckBoxGenerateBatch.IsChecked == true)
{
var batch = new Batch(ProjectType, Version, Build, Projects.DownloadPath, "launch.bat");
batch.Create();
}
if (CheckBoxGenerateEula.IsChecked == true)
{
var eula = new Eula( Projects.DownloadPath, true);
eula.Create();
}
}

Expand Down
2 changes: 2 additions & 0 deletions PaperDownloader/PaperDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Launch\Batch.cs" />
<Compile Include="Launch\Eula.cs" />
<Compile Include="Servers\Versions\Projects.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
Expand Down
2 changes: 1 addition & 1 deletion PaperDownloader/ResourceDictionaries/Grid.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

<Style TargetType="Grid"
x:Key="GridContainer">
<Setter Property="Margin" Value="20"/>
<Setter Property="Margin" Value="10"/>
</Style>
</ResourceDictionary>

0 comments on commit c4c1c59

Please sign in to comment.