Skip to content

Commit

Permalink
get rid of external Zip library
Browse files Browse the repository at this point in the history
added build version auto increment
  • Loading branch information
0uti committed Nov 26, 2018
1 parent 693451d commit 519217e
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 75 deletions.
10 changes: 5 additions & 5 deletions BuildTools/BuildTools.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions BuildTools/BuildTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public BuildTools(Guid guid, Job job) {
}

// Run BuildTools Button Clicked
private void runBT_Click(object sender, EventArgs e) {
private void RunBT_Click(object sender, EventArgs e) {
bool update = autoUpdateCB.Checked;
string version;
if (versionBox.SelectedIndex == 0) {
Expand All @@ -94,7 +94,7 @@ private void runBT_Click(object sender, EventArgs e) {
}

// Update BuildTools Button Clicked
private void updateBT_Click(object sender, EventArgs e) {
private void UpdateBT_Click(object sender, EventArgs e) {

Thread thread = new Thread(delegate() {
_runner.UpdateJar();
Expand All @@ -106,14 +106,14 @@ private void updateBT_Click(object sender, EventArgs e) {
}

// Clear Log Button Clicked
private void clearBT_Click(object sender, EventArgs e) {
private void ClearBT_Click(object sender, EventArgs e) {
_lastLog += outputTB.Text;
outputTB.Text = "";
undoBT.Visible = true;
}

// Undo Button Clicked
private void undoBT_Click(object sender, EventArgs e) {
private void UndoBT_Click(object sender, EventArgs e) {
outputTB.Text = _lastLog + outputTB.Text;
_lastLog = "";
undoBT.Visible = false;
Expand Down Expand Up @@ -231,7 +231,7 @@ private void BuildTools_FormClosed(object sender, FormClosedEventArgs e) {
}

// Source link clicked
private void linkLabel_Click(object sender, LinkLabelLinkClickedEventArgs e) {
private void LinkLabel_Click(object sender, LinkLabelLinkClickedEventArgs e) {
System.Diagnostics.Process.Start("https://github.com/0uti/BuildToolsGUI");
}

Expand Down
12 changes: 7 additions & 5 deletions BuildTools/BuildTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@
<EmbedInteropTypes>False</EmbedInteropTypes>
<Private>True</Private>
</Reference>
<Reference Include="DotNetZip, Version=1.11.0.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.11.0\lib\net20\DotNetZip.dll</HintPath>
<Private>True</Private>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
Expand All @@ -103,6 +98,8 @@
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Web" />
<Reference Include="System.Xaml" />
Expand Down Expand Up @@ -182,6 +179,11 @@
<Error Condition="!Exists('..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets'))" />
</Target>
<Import Project="..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets" Condition="Exists('..\packages\MSBuild.ILMerge.Task.1.0.5\build\MSBuild.ILMerge.Task.targets')" />
<ProjectExtensions>
<VisualStudio>
<UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_StartDate="2000/1/1" BuildVersion_UpdateFileVersion="True" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.None.Increment" />
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
30 changes: 15 additions & 15 deletions BuildTools/JobObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Job : IDisposable {
static extern IntPtr CreateJobObject(IntPtr a, string lpName);

[DllImport("kernel32.dll")]
static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, UInt32 cbJobObjectInfoLength);
static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, uint cbJobObjectInfoLength);

[DllImport("kernel32.dll", SetLastError = true)]
static extern bool AssignProcessToJobObject(IntPtr job, IntPtr process);
Expand Down Expand Up @@ -74,33 +74,33 @@ public bool AddProcess(int processId) {

[StructLayout(LayoutKind.Sequential)]
struct IO_COUNTERS {
public UInt64 ReadOperationCount;
public UInt64 WriteOperationCount;
public UInt64 OtherOperationCount;
public UInt64 ReadTransferCount;
public UInt64 WriteTransferCount;
public UInt64 OtherTransferCount;
public ulong ReadOperationCount;
public ulong WriteOperationCount;
public ulong OtherOperationCount;
public ulong ReadTransferCount;
public ulong WriteTransferCount;
public ulong OtherTransferCount;
}


[StructLayout(LayoutKind.Sequential)]
struct JOBOBJECT_BASIC_LIMIT_INFORMATION {
public Int64 PerProcessUserTimeLimit;
public Int64 PerJobUserTimeLimit;
public UInt32 LimitFlags;
public long PerProcessUserTimeLimit;
public long PerJobUserTimeLimit;
public uint LimitFlags;
public UIntPtr MinimumWorkingSetSize;
public UIntPtr MaximumWorkingSetSize;
public UInt32 ActiveProcessLimit;
public uint ActiveProcessLimit;
public UIntPtr Affinity;
public UInt32 PriorityClass;
public UInt32 SchedulingClass;
public uint PriorityClass;
public uint SchedulingClass;
}

[StructLayout(LayoutKind.Sequential)]
public struct SECURITY_ATTRIBUTES {
public UInt32 nLength;
public uint nLength;
public IntPtr lpSecurityDescriptor;
public Int32 bInheritHandle;
public int bInheritHandle;
}

[StructLayout(LayoutKind.Sequential)]
Expand Down
5 changes: 2 additions & 3 deletions BuildTools/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down Expand Up @@ -32,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.0.2.36")]
[assembly: AssemblyFileVersion("1.0.2.36")]
103 changes: 62 additions & 41 deletions BuildTools/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
using System.Net;
using System.IO;
using System.Threading;
using Ionic.Zip;
using Microsoft.Win32;
using Newtonsoft.Json.Linq;

using System.IO.Compression;

namespace BuildTools {

Expand Down Expand Up @@ -74,8 +73,7 @@ public bool CheckUpdate(out bool bad) {
}
if (File.Exists(Dir + (string) _json["buildTools"]["name"])) {
int number = (int) _api["number"];
int currentBuildNumber;
bool success = GetBuildNumberFromJar(out currentBuildNumber);
bool success = GetBuildNumberFromJar(out int currentBuildNumber);

if (success) {
bool update = currentBuildNumber < number;
Expand Down Expand Up @@ -158,25 +156,27 @@ private JObject DownloadJson(string url) {
/// </summary>
/// <param name="i">The build number of the jar</param>
/// <returns>Whether the jar file is valid.</returns>
private bool GetBuildNumberFromJar(out int i) {
private bool GetBuildNumberFromJar(out int i)
{
_form.AppendText("Checking downloaded BuildTools");
try {
using (ZipFile zip = ZipFile.Read(Dir + (string) _json["buildTools"]["name"])) {
ZipEntry entry = zip["META-INF/MANIFEST.MF"];
using (MemoryStream stream = new MemoryStream()) {
entry.Extract(stream);
stream.Position = 0;

StreamReader reader = new StreamReader(stream);

try
{
using (ZipArchive zip = ZipFile.OpenRead(Dir + (string)_json["buildTools"]["name"]))
{
ZipArchiveEntry entry = zip.GetEntry("META-INF/MANIFEST.MF");
using (StreamReader reader = new StreamReader(entry.Open()))
{
string line;
while ((line = reader.ReadLine()) != null) {
if (line.StartsWith("Implementation-Version: ")) {
while ((line = reader.ReadLine()) != null)
{
if (line.StartsWith("Implementation-Version: "))
{
string version = line.Replace("Implementation-Version: ", "");
string[] split = version.Split('-');

// at least put some effort into making sure this is a BuildTools jar
if (!"git".Equals(split[0]) || !"BuildTools".Equals(split[1])) {
if (!"git".Equals(split[0]) || !"BuildTools".Equals(split[1]))
{
_form.AppendText("Jar is invalid");
i = 0;
return false;
Expand All @@ -190,7 +190,9 @@ private bool GetBuildNumberFromJar(out int i) {
i = 0;
return false;
}
} catch (Exception) {
}
catch (Exception)
{
_form.AppendText("Jar is invalid");
i = 0;
return false;
Expand All @@ -208,8 +210,7 @@ public bool UpdateJar() {
_form.AppendText("Checking for update");
_form.ProgressShow();
_form.ProgressIndeterminate();
bool bad;
bool update = CheckUpdate(out bad);
bool update = CheckUpdate(out bool bad);
if (update) {
_form.AppendText("Update needed for BuildTools");
if (!GetJson()) {
Expand Down Expand Up @@ -269,63 +270,84 @@ public void RunBuildTools(bool autoUpdate, string version) {
}

// Java check
bool javaInstalled;
if (!CheckJava(out javaInstalled)) {
string javaFile = Dir + (string) _json["java"]["name"];
if (!javaInstalled) {
if (!CheckJava(out bool javaInstalled))
{
string javaFile = Dir + (string)_json["java"]["name"];
if (!javaInstalled)
{
// Java is not installed
_form.AppendText("Downloading Java installer");

bool success = DownloadJava(javaFile);
if (!success) {
if (!success)
{
_form.AppendText("Java could not be downloaded, canceling");
}

_form.ProgressIndeterminate();
success = InstallJava(javaFile);
if (!success) {
if (!success)
{
_form.AppendText("Java could not be installed, canceling");
}

if (CheckJava()) {
if (CheckJava())
{
_form.AppendText("Java installed successfully");
} else {
}
else
{
_form.AppendText("Java could not be installed, canceling");
return;
}
} else {
}
else
{
// Java is installed
_form.AppendText("This is a 64 bit operating system, but the 32 bit JRE is installed. Downloading 64 bit JRE");
bool success = DownloadJava(javaFile);
if (!success) {
if (!success)
{
_form.AppendText("Unable to download the 64 bit Java installer, will continue with the 32 bit JRE. This may cause the build to fail");
} else {
}
else
{
_form.AppendText("Uninstalling current 32 bit JRE");
success = UninstallJava();
if (!success) {
if (!success)
{
_form.AppendText("There was an error while attempting to uninstall the 32 bit JRE");
CheckJava(out javaInstalled);
if (javaInstalled) {
if (javaInstalled)
{
_form.AppendText("Java still seems to be installed, though. Will continue with the 32 bit JRE. This may cause the build to fail");
} else {
}
else
{
_form.AppendText("In spite of the error, it seems Java has been uninstalled. Will now install the 64 bit JRE");
success = InstallJava(javaFile);
if (!success) {
if (!success)
{
_form.AppendText("Java failed to install, canceling");
return;
}
if (!FullJavaCheck()) {
if (!FullJavaCheck())
{
return;
}
}
} else {
}
else
{
_form.AppendText("Installing the 64 bit JRE");
success = InstallJava(javaFile);
if (!success) {
if (!success)
{
_form.AppendText("Java failed to install, canceling");
return;
}
if (!FullJavaCheck()) {
if (!FullJavaCheck())
{
return;
}
}
Expand Down Expand Up @@ -474,8 +496,7 @@ private bool UninstallJava() {
}

private bool CheckJava() {
bool what;
return CheckJava(out what);
return CheckJava(out bool what);
}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion BuildTools/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotNetZip" version="1.11.0" targetFramework="net45" />
<package id="HtmlAgilityPack" version="1.8.4" targetFramework="net45" />
<package id="ILMerge" version="2.13.0307" targetFramework="net45" />
<package id="MSBuild.ILMerge.Task" version="1.0.5" targetFramework="net45" />
Expand Down

0 comments on commit 519217e

Please sign in to comment.