Skip to content

Commit

Permalink
Little fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbilas committed Dec 1, 2024
1 parent e531e72 commit 25a4896
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/Unity.Cli/Commands_RunUnity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,15 @@ public static CliExitCode RunUnity(CommandContext context)
unityProject = tryUnityProject;
projectPath = unityProject.Path;

// should never happen, unless i am debugging something in a project :)
string? projectVersion = null;
try
if (unityProject.HasProjectVersionTxt()) // missing projectversion.txt can be for test and monorepo projects
{
projectVersion = unityProject.GetVersion().ToString();
try
{
projectVersion = unityProject.GetVersion().ToString();
}
catch (UnityVersionFormatException) { projectVersion = "<invalid format>"; }
}
catch (UnityVersionFormatException) { projectVersion = "<invalid format>"; }
// these are ok, for test projects
catch (FileNotFoundException) {}
catch (DirectoryNotFoundException) {}

if (projectVersion != null)
Console.Write($"Loading project at {unityProject.Path}; expects {projectVersion}");
Expand Down
10 changes: 7 additions & 3 deletions src/Unity/UnityProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public object Output(StructuredOutputLevel level, bool debug)
var output = Expando.From(new
{
Path,
Version = GetVersion().ToString(),
Version = HasProjectVersionTxt() ? GetVersion().ToString() : "<missing ProjectVersion.txt>",
Created = GetCreationTime().ToNiceAge(true),
LastOpened = GetLastOpenedTime()?.ToNiceAge(true) ?? "never",
});
Expand Down Expand Up @@ -51,10 +51,14 @@ public UnityVersion GetVersion()
return UnityVersion.FromUnityProjectVersionTxt(projectVersionNPath);
}

public bool HasProjectVersionTxt() =>
_projectRoot.Combine(UnityProjectConstants.ProjectVersionTxtNPath).FileExists();

public IEnumerable<UnityVersion> GetTestableVersions()
{
var projectVersion = GetVersion();
yield return projectVersion;
var projectVersion = HasProjectVersionTxt() ? GetVersion() : null;
if (projectVersion != null)
yield return projectVersion;

var editorsYml = _projectRoot.ParentContaining(UnityConstants.EditorsYmlFileName, true);
if (editorsYml is null)
Expand Down

0 comments on commit 25a4896

Please sign in to comment.