Skip to content

Feature/os detection#31

Merged
aevitas merged 11 commits into
aevitas:masterfrom
maximilianmaihoefner:feature/os-detection
Apr 29, 2020
Merged

Feature/os detection#31
aevitas merged 11 commits into
aevitas:masterfrom
maximilianmaihoefner:feature/os-detection

Conversation

@maximilianmaihoefner
Copy link
Copy Markdown
Contributor

This is just my initial WIP Draft for #28 some things definitely still need work and cleanup, but I feel like its a good Point to stop for now and have some discussions about my approach and if you had something different in mind or some input in general. Feel free to tear it apart :)

Comment thread Patcher/BinarySearcher.cs
Comment thread Patcher/UnityInstallation.cs Outdated
@maximilianmaihoefner maximilianmaihoefner marked this pull request as ready for review April 22, 2020 14:23
@maximilianmaihoefner maximilianmaihoefner changed the title [WIP] Feature/os detection Feature/os detection Apr 22, 2020
@maximilianmaihoefner
Copy link
Copy Markdown
Contributor Author

I did some more work on this and feel like its in a good state right now, feel free to point out parts you are not satisfied with and I can go back and change them.

The additional workflow now works as follows:

  1. You start the Patcher without any arguments.
  2. The Patcher tries to find Unity installations in the default location depending on the OS.
  3. The User gets shown a selection menu from which he can easily select a Version which should get patched, and also immediately sees if that version is supported or not.
    4.a If a supported version is chosen, the patch is applied with the new BinarySearcher.
    4.b If an unsupported version is chosen, the user gets an additional selection menu to chose which patch he wants to apply. and the patch is applied using the new BinarySearcher.

All the old options should still work the same, the new logic only triggers then the -e Flag is missing.

@aevitas aevitas linked an issue Apr 24, 2020 that may be closed by this pull request
Copy link
Copy Markdown
Owner

@aevitas aevitas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely fantastic work. I think this could mark the start of a version 2.0 of the patcher with how many features this introduces. I've left a few (sometimes nitpicky) notes here and there, but overall this looks very good.

Comment thread Patcher/Patches.cs Outdated
@@ -0,0 +1,106 @@
namespace Patcher
{
using System;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The using directives should be above the namespace declaration for consistency

Comment thread Patcher/ConsoleUtility.cs
/// <typeparam name="T">The type of a single option</typeparam>
/// <returns>The selected option from the list</returns>
public static T ShowSelectionMenu<T>(List<T> options, Func<T, string> optionLine)
{
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this just be a private method in the Program.cs file? I'm not big on Utility classes, much less when they only have a single utility.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to keep the amount of Code in the Program.cs down to make it less cluttered and easier to read. If you prefer it in the Program.cs I can move it over, shouldn't be that bad.

Comment thread Patcher/UnityInstallation.cs Outdated
/// <param name="operatingSystem"></param>
public UnityInstallation(string installationLocation, OperatingSystem operatingSystem)
{
_installationLocation = installationLocation;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since almost none of the API of this class would work when this is null, it'd probably make sense to add a precondition check along the lines of _installationLocation = installationLocation ?? throw new ArgumentNullException(nameof(installLocation));

Comment thread Patcher/UnityInstallation.cs Outdated
{
foreach (PatchInfo patch in patches)
{
if (Regex.IsMatch(this.Version, patch.Version))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't required here. Also, assuming this gets passed values such as 2020.1, does this work? I didn't realize you could use regular expressions like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overlooked the this when I was trying to remove all of them.

The Regex.IsMatch returns true if the pattern (patch.Version) is contained at least once in the input (Version), examples would be:

patch.Version Version Result
2018.4 2018.4.1f1 true
2018 2018.4.22f1 true
2020.2 2020.2.0a2 true
2019.3.6f1 2019.3.6f1 true
2019.3.6f1 2019.3.7f1 false

This allows us to specify patches for more than once specific Version of Unity, which is handy because I saw that for Windows the entire 2018 Release Cycle has the same PatchInfo.

One thing that might come back to bite us is that it will return the first patch.Version that matches, which might lead to problems when for Example 2020.2.1f1 needs a special Patch but the rest of the 2020.2 Cycle has the same Patch, then it might return the general 2020.2 one instead of the 2020.2.1f1 one. But I have not seen something like that thus far, so I figured we can work that out when it comes to it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might also make sense to add some Unit Tests for that Method, if you tell me which Framework you prefer for Testing I can add some if you want.

Comment thread Patcher/UnityInstallation.cs Outdated
var installations = new UnityInstallation[directories.Length];
for (var i = 0; i < directories.Length; i++)
{
installations[i] = new UnityInstallation(directories[i], operatingSystem);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fairly sure you could just yield return these and forego allocating the array here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, although I also had to remove the try-catch since you can't yield return from within a try-catch block. But nothing here should throw an UnauthorizedAccessException so it should be fine

Comment thread Patcher/UnityInstallation.cs Outdated
_ => throw new ArgumentOutOfRangeException(nameof(operatingSystem))
};

if (Directory.Exists(path))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inverting the if here could reduce nesting:

if (!Directory.Exists(path))
    return Enumerable.Empty<UnityInstallation>();

@maximilianmaihoefner
Copy link
Copy Markdown
Contributor Author

@aevitas Thanks for the Feedback, glad you like it. I think I resolved everything you mentioned, if I forgot something or you find something else let me know.

@aevitas aevitas merged commit 18ab41b into aevitas:master Apr 29, 2020
@aevitas
Copy link
Copy Markdown
Owner

aevitas commented Apr 29, 2020

Thanks for the great contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] OS Detection and Version selection

2 participants