Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another stable build of v2 #38

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
c7fa87f
Cleaned up for rewrite and renamed everything to Hephaestus
CreepPork Sep 27, 2018
37b80b8
Added Hephaestus Configurator backbone
CreepPork Sep 27, 2018
ed94709
Development
CreepPork Sep 28, 2018
ae06358
Some more development
CreepPork Oct 5, 2018
4a001bc
Updated all to .NET Framework 4.6.2
CreepPork Oct 5, 2018
dd6c11b
Added JSON setting writing and reading
CreepPork Oct 5, 2018
93b5ad7
Renamed AddonBuilder to Hephaestus
CreepPork Oct 8, 2018
9ae3140
Added principle of Hephaestus
CreepPork Oct 8, 2018
bee6ae4
Updated principle
CreepPork Oct 8, 2018
5339ce7
Fixed principle
CreepPork Oct 8, 2018
baaeb3a
Reworked settings
CreepPork Oct 12, 2018
2fa3671
Added fully functional PBO building
CreepPork Oct 12, 2018
d7ab559
Added Hephaestus Configurator data saving
CreepPork Oct 12, 2018
8a60051
Added support for game launching and shutdown, various fixes and opti…
CreepPork Oct 13, 2018
ffde5e7
Added time measurement when build is completed
CreepPork Oct 13, 2018
f7300ff
Fixed project prefixes and included files
CreepPork Oct 13, 2018
059b817
Refactored init and help commands to separate methods
CreepPork Oct 14, 2018
bb93133
Added version command
CreepPork Oct 14, 2018
e0fda6e
Only automate the build number
CreepPork Oct 14, 2018
f3926a2
Added Save method to Project class
CreepPork Oct 14, 2018
fdf4072
Added primitive command init support through the command line
CreepPork Oct 14, 2018
174b90a
Removed unneeded exceptions
CreepPork Oct 14, 2018
0029f76
Added hash support and rebuild
CreepPork Oct 14, 2018
18934a4
Added JSON field loading to Hephaestus Configurator
CreepPork Oct 14, 2018
ae3157d
Added argument support for Hephaestus Configurator
CreepPork Oct 14, 2018
f39f4eb
Added armake libraries and icon for Hephaestus
CreepPork Oct 14, 2018
5724a2e
Added armake support
CreepPork Oct 14, 2018
3bd3e5c
Increased MAXINCLUDES to 128
CreepPork Oct 15, 2018
0a11a87
Fixed bugs and cleaned up code with ReSharper
CreepPork Nov 6, 2018
3ef5f73
Addressed complaints from Codeacy
CreepPork Nov 6, 2018
15c051c
Code refactoring
CreepPork Nov 6, 2018
e318bc4
Addressed Malice's Game review
CreepPork Nov 6, 2018
b2ee5bb
Addressed Malice's loop review
CreepPork Nov 6, 2018
eee84de
Merge branch 'master' into develop
CreepPork Nov 6, 2018
bfc694e
Fixed Codacy complaints
CreepPork Nov 6, 2018
5cb1dd7
Added missing arguments to help command
CreepPork Nov 10, 2018
b33610a
Ported Hephaestus to .NET Core
CreepPork Nov 11, 2018
9c902be
Fixed some bugs
CreepPork Nov 11, 2018
32f8b52
Added master list for Configurator
CreepPork Nov 11, 2018
a75cfbf
Versioning
CreepPork Nov 11, 2018
a625244
Fixed reference issues
CreepPork Dec 3, 2018
7c893de
Added logo to Common
CreepPork Jan 2, 2019
2e51975
Fixed "Rebuild?" question not working, fixed #33
CreepPork Jan 2, 2019
b3761b9
Refactoring
CreepPork Jan 2, 2019
e877870
Refactoring and custom builder support #35 #36
CreepPork Jan 2, 2019
0370c2f
Removed useless comment
CreepPork Jan 3, 2019
2e8058b
Refactoring
CreepPork Jan 3, 2019
3027f16
Removed hashes from Project constructor
CreepPork Jan 3, 2019
cdef295
Added recursive search for .hephaestus.json
CreepPork Jan 3, 2019
7ca961f
Reworked Hephaestus console init command
CreepPork Jan 3, 2019
2a4d3b1
Refactoring and code documentation.
CreepPork Jan 3, 2019
6903281
Refactoring and code documentation.
CreepPork Jan 3, 2019
e4db0b7
Refactoring and code documentation.
CreepPork Jan 3, 2019
a429e93
Merge branch 'master' into develop
CreepPork Jan 3, 2019
c078ebc
Added Mike's icon
CreepPork Jan 6, 2019
5584777
Revert "Merge branch 'master' into develop"
CreepPork Jan 3, 2019
3296de5
Merge remote-tracking branch 'origin/develop' into develop
CreepPork Jan 6, 2019
f7fc2cd
Revert "Merge remote-tracking branch 'origin/develop' into develop"
CreepPork Jan 6, 2019
2c96af7
Fixed game not closing, fixed #39
CreepPork Jan 12, 2019
9382fbe
Fixed wrong counting of directories that were built, fixed #40
CreepPork Feb 18, 2019
9387035
Fixed null reference exception #40
CreepPork Feb 19, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Hephaestus.Common/Classes/Driver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Hephaestus.Common.Classes
{
public class Driver
{
public string Name { get; }
public string Path { get; }
public string Arguments { get; }

public Driver(string name, string path, string arguments)
{
Name = name;
Path = path;
Arguments = arguments;
}
}
}
79 changes: 79 additions & 0 deletions Hephaestus.Common/Classes/Game.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Diagnostics;
using System.IO;
using Hephaestus.Common.Utilities;

namespace Hephaestus.Common.Classes
{
public class Game
{
public string GameExecutable { get; }
public string GameExecutableArguments { get; }

public Game(string gameExecutable, string gameExecutableArguments)
{
GameExecutable = gameExecutable;
GameExecutableArguments = gameExecutableArguments;
}

/// <summary>
/// Launch the game.
/// </summary>
/// <param name="game">Game data.</param>
public static void Launch(Game game)
{
try
{
ConsoleUtility.Info($"Starting {Path.GetFileName(game.GameExecutable)}");

Process.Start(new ProcessStartInfo(game.GameExecutable, game.GameExecutableArguments));
}
catch (Exception e)
{
ConsoleUtility.Error($"Failed to start {game.GameExecutable} because {e.Message}");
}
}

/// <summary>
/// Close the process.
/// </summary>
/// <param name="processToShutdown">Process to terminate.</param>
public static void Shutdown(string processToShutdown)
{
// Get all processes running.
Process[] allProcesses = Process.GetProcesses();

// Loop through each process.
foreach (Process process in allProcesses)
{
// Turn the process name into lowercase for any inconsistencies between naming.
string processName = process.ProcessName.ToLower();

// If the process name doesn't match process to shutdown then we move on onto the next item in the loop.
if (processToShutdown != processName)
{
continue;
}

ConsoleUtility.Info($"Found {processName}. Terminating process...");

try
{
// Shutdown the process.
if (! process.HasExited)
{
process.CloseMainWindow();

process.WaitForExit();
}

process.Close();
}
catch (Exception e)
{
ConsoleUtility.Error($"error: Failed to shutdown {process} because {e.Message}");
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Security.Cryptography;
using System.Text;

namespace HephaestusCommon.Classes
namespace Hephaestus.Common.Classes
{
public class Hash
{
Expand All @@ -20,6 +20,11 @@ public Hash(string directoryName)

public string Sha1 { get; set; }

/// <summary>
/// Loop through each file in the given directory and create a SHA1 checksum from all the files inside the directory combined.
/// </summary>
/// <param name="directory">The directory for which to return the SHA1 checksum.</param>
/// <returns>SHA1 checksum.</returns>
private static string HashDirectory(string directory)
{
string[] files = Directory.GetFiles(directory, "*", SearchOption.AllDirectories)
Expand Down
8 changes: 8 additions & 0 deletions Hephaestus.Common/Classes/PathType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Hephaestus.Common.Classes
{
public enum PathType
{
Directory,
File
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Collections.Generic;
using HephaestusCommon.Utilities;
using Hephaestus.Common.Utilities;

namespace HephaestusCommon.Classes
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global | If set from properties are removed then JSON returns them as null/false.
// ReSharper disable MemberCanBePrivate.Global | Same as above.

namespace Hephaestus.Common.Classes
{
public class Project
{
Expand All @@ -10,28 +13,25 @@ public Project()
{
}

public Project(string projectDirectory, string sourceDirectory, string targetDirectory,
string addonBuilderFile, string projectPrefix, string privateKeyFile,
Game game, bool shutdownGameBeforeBuilding, bool startGameAfterBuilding)
public Project(string projectDirectory, string sourceDirectory, string targetDirectory, string projectPrefix, string privateKeyFile, Game game, bool shutdownGameBeforeBuilding, bool startGameAfterBuilding, string selectedDriver, List<Driver> drivers)
{
ProjectDirectory = projectDirectory;
SourceDirectory = sourceDirectory;
TargetDirectory = targetDirectory;
AddonBuilderFile = addonBuilderFile;
ProjectPrefix = projectPrefix;
PrivateKeyFile = privateKeyFile;
Game = game;
ShutdownGameBeforeBuilding = shutdownGameBeforeBuilding;
StartGameAfterBuilding = startGameAfterBuilding;
SelectedDriver = selectedDriver;
Drivers = drivers;
}

public string ProjectDirectory { get; set; }

public string SourceDirectory { get; set; }
public string TargetDirectory { get; set; }

public string AddonBuilderFile { get; set; }

public string ProjectPrefix { get; set; }

public string PrivateKeyFile { get; set; }
Expand All @@ -41,11 +41,16 @@ public Project(string projectDirectory, string sourceDirectory, string targetDir
public bool ShutdownGameBeforeBuilding { get; set; }
public bool StartGameAfterBuilding { get; set; }

public bool UseArmake { get; set; }

// Directory name, SHA1
public Dictionary<string, Hash> Hashes { get; set; }

public string SelectedDriver { get; set; }

public List<Driver> Drivers { get; set; }

/// <summary>
/// Save the current instance of this class to JSON.
/// </summary>
public void Save()
{
ProjectUtility.SetProject(ProjectDirectory, this);
Expand Down
24 changes: 24 additions & 0 deletions Hephaestus.Common/Hephaestus.Common.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Deterministic>False</Deterministic>
<ApplicationIcon>Resources\Hephaestus.ico</ApplicationIcon>
<Authors>ArmaAchilles</Authors>
<Description>Shared library for Hephaestus.</Description>
<Copyright>Copyright © ArmaAchilles 2018</Copyright>
<PackageLicenseUrl>https://github.com/ArmaAchilles/Hephaestus/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/ArmaAchilles/Hephaestus</PackageProjectUrl>
<PackageIconUrl>https://github.com/ArmaAchilles/Achilles/blob/master/Pictures/logo/achilles_logo_transparentBackground.png?raw=true</PackageIconUrl>
<RepositoryUrl>https://github.com/ArmaAchilles/Hephaestus</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<NeutralLanguage />
<AssemblyVersion>1.0.0.*</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>

</Project>
Binary file added Hephaestus.Common/Resources/Hephaestus.ico
Binary file not shown.
120 changes: 120 additions & 0 deletions Hephaestus.Common/Utilities/ConsoleUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System;
using System.IO;
using Hephaestus.Common.Classes;

namespace Hephaestus.Common.Utilities
{
public static class ConsoleUtility
{
/// <summary>
/// Loops till the user gives a Y or N answer which then is converted into a boolean.
/// </summary>
/// <param name="question">Question to ask the user. Question is transformed into 'questionHere (Y/N): '.</param>
/// <returns>Returns true if user selected yes and returns false if user selected no.</returns>
public static bool AskYesNoQuestion(string question)
{
bool result;

while (true)
{
Console.Write($"{question} (Y/N): ");
string key = Console.ReadLine()?.ToLower();

if (key == "y")
{
result = true;
break;
}

if (key == "n")
{
result = false;
break;
}

Console.WriteLine("Incorrect selection. Try again.");
}

return result;
}

/// <summary>
/// Ask the user to enter a string.
/// </summary>
/// <param name="message">Message displayed to the user. Message is transformed into 'messageHere: '.</param>
/// <returns></returns>
public static string AskToEnterString(string message)
{
Console.Write($"{message}: ");

string enteredString = Console.ReadLine();

return enteredString;
}

/// <summary>
/// Ask the user to enter either a directory or a file path.
/// </summary>
/// <param name="message">Message displayed to the user. Message is transformed into 'messageHere: '.</param>
/// <param name="pathType">Select what type of path should the user enter.</param>
/// <returns>Path to the directory or file.</returns>
public static string AskToEnterPath(string message, PathType pathType)
{
string enteredString;
while (true)
{
Console.Write($"{message}: ");

enteredString = Console.ReadLine();

if (pathType == PathType.Directory)
{
if (Directory.Exists(enteredString))
{
break;
}

Console.WriteLine("That is not a valid directory. Try again.");
}
else
{
if (File.Exists(enteredString))
{
break;
}

Console.WriteLine("That is not a valid file. Try again.");
}
}

return enteredString;
}

/// <summary>
/// Logs an error message to the console.
/// </summary>
/// <param name="message">Message to the user. Message is transformed into 'error: messageHere'.</param>
public static void Error(string message)
{
Console.Error.WriteLine($"error: {message}");
}

/// <summary>
/// Logs a warning to the console.
/// </summary>
/// <param name="message">Message to the user. Message is transformed into 'warning: messageHere'.</param>
public static void Warning(string message)
{
Console.WriteLine($"warning: {message}");
}

/// <summary>
/// Logs an info message to the console.
/// </summary>
/// <param name="message">Message to the user. Message is transformed into 'info: messageHere'.</param>
public static void Info(string message)
{
Console.WriteLine($"info: {message}");
}
}
}
34 changes: 34 additions & 0 deletions Hephaestus.Common/Utilities/DriverUtility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Hephaestus.Common.Classes;

namespace Hephaestus.Common.Utilities
{
public static class DriverUtility
{
/// <summary>
/// Gets the currently selected driver from JSON and casts it to the Driver class.
/// </summary>
/// <param name="project">Project data.</param>
/// <returns>Selected driver.</returns>
/// <exception cref="ArgumentException">If the selected driver does not exist in the Drivers list in the JSON.</exception>
public static Driver GetSelectedDriver(Project project)
{
Driver selectedDriver = null;

foreach (Driver driver in project.Drivers)
{
if (driver.Name == project.SelectedDriver)
{
selectedDriver = driver;
}
}

if (selectedDriver == null)
{
throw new ArgumentException($"{project.SelectedDriver} is an invalid driver. Select another driver and try again.");
}

return selectedDriver;
}
}
}
Loading