Skip to content

Commit 10f8cd6

Browse files
Merge pull request #36 from chrisyarbrough/#32-cant-open-project-on-windows
Fix #32 cant open project on windows
2 parents 1c7dd82 + 9a89bb8 commit 10f8cd6

File tree

9 files changed

+44
-97
lines changed

9 files changed

+44
-97
lines changed

README.md

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A terminal command to open Unity projects quickly from the command line.
88

99
- macOS
1010
- Windows
11-
- Linux
11+
- Linux (TBD)
1212

1313
## Commands
1414

@@ -44,32 +44,7 @@ If the `version` argument is omitted, an interactive prompt shows all installed
4444

4545
## Installation
4646

47-
### NuGet Global Tool
48-
49-
The easiest way to install `ucll` is as a .NET global tool via NuGet:
50-
51-
```shell
52-
dotnet tool install --global UnityCommandLineLauncher
53-
```
54-
55-
**Requirements:**
56-
- [.NET 10.0](https://dotnet.microsoft.com/download) or newer
57-
58-
> If you don't want to install .NET just for this tool, you can use a self-contained (standalone) binary, see below.
59-
60-
**Updating:**
61-
```shell
62-
dotnet tool update --global UnityCommandLineLauncher
63-
```
64-
65-
**Uninstalling:**
66-
```shell
67-
dotnet tool uninstall --global UnityCommandLineLauncher
68-
```
69-
70-
After installation, the `ucll` command will be available globally in your terminal.
71-
72-
### From Source
47+
### From Source (recommended)
7348

7449
1. Clone the repository.
7550
2. Checkout a release tag and take note of the signature, e.g. `git tag -v v1.0.0`.

src/ucll.build/Publishing.md

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,14 @@
11
# Publishing (for Maintainers)
22

3-
## GitHub Release (Self-Contained Binary)
4-
5-
The GitHub `release.yml` workflow takes care of running this project to produce binaries for each platform and then
3+
The GitHub `release.yml` workflow takes care of running this project to produce binaries and then
64
signs them before uploading a new release.
75

8-
If this is not available, and we need to publish locally:
6+
To publish locally:
7+
98
Install the `gpg` utility to let the publish process sign release artifacts with your personal key.
109

1110
```shell
1211
dotnet run
1312
```
1413

15-
Artifacts are signed with the default key which you have configured (or the first secret key it finds).
16-
17-
## Dotnet Tool
18-
19-
```shell
20-
PACK_DIR=bin/pack
21-
BUILD_DIR=$PACK_DIR/build
22-
dotnet pack ../ucll/ucll.csproj \
23-
-p:PackAsTool=true \
24-
-p:ToolCommandName=ucll \
25-
-p:PackageId=UnityCommandLineLauncher \
26-
-p:Authors="Chris Yarbrough" \
27-
-p:PackageLicenseExpression=MIT \
28-
-p:PackageReadmeFile=README.md \
29-
-p:PackageTags="Unity CLI Hub" \
30-
-p:RepositoryUrl=https://github.com/chrisyarbrough/UnityCommandLineLauncher \
31-
-p:RepositoryType=git \
32-
-p:OutputPath=$BUILD_DIR \
33-
-p:PublishDir=$BUILD_DIR \
34-
--output ../ucll/$PACK_DIR
35-
```
36-
37-
```shell
38-
dotnet nuget push ../ucll/bin/pack/UnityCommandLineLauncher.*.nupkg --api-key <your-key> --source https://apiint.nugettest.org/v3/index.json
39-
```
40-
41-
```
42-
https://api.nuget.org/v3/index.json
43-
```
14+
Artifacts are signed with the default key which you have configured (or the first secret key it finds).
Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1-
using System.Runtime.InteropServices;
2-
31
public class PlatformSupportTests
42
{
5-
[Fact_PlatformOSX]
6-
public void FindInstallationRootReturnsValidRoot()
3+
[Theory]
4+
[InlineData(typeof(MacSupport),
5+
"/Applications/Unity/Hub/Editor/2022.3.10f1/Unity.app/Contents/MacOS/Unity",
6+
"/Applications/Unity/Hub/Editor/2022.3.10f1")]
7+
[InlineData(typeof(WindowsSupport),
8+
@"C:\Program Files\Unity\Hub\Editor\6000.0.59f2\Editor\Unity.exe",
9+
@"C:\Program Files\Unity\Hub\Editor\6000.0.59f2")]
10+
public void FindInstallationRootReturnsValidRoot(Type platformSupportType, string editorPath, string expectedRoot)
711
{
8-
PlatformSupport platformSupport = PlatformSupport.Create();
9-
const string editorPath = "/Applications/Unity/Hub/Editor/2022.3.10f1/Unity.app/Contents/MacOS/Unity";
12+
PlatformSupport platformSupport = (Activator.CreateInstance(platformSupportType) as PlatformSupport)!;
1013
string root = platformSupport.FindInstallationRoot(editorPath);
11-
Assert.Equal("/Applications/Unity/Hub/Editor/2022.3.10f1", root);
12-
}
13-
14-
// ReSharper disable once InconsistentNaming
15-
private sealed class Fact_PlatformOSX : FactAttribute
16-
{
17-
public Fact_PlatformOSX()
18-
{
19-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
20-
{
21-
Skip = "Test only runs on macOS";
22-
}
23-
}
14+
Assert.Equal(expectedRoot, root);
2415
}
2516
}

src/ucll/Shared/Platform/LinuxSupport.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
internal sealed class LinuxSupport : PlatformSupport
22
{
3+
public override string FindInstallationRoot(string editorPath)
4+
{
5+
throw new NotImplementedException();
6+
}
7+
38
public override string FormatHubArgs(string args)
49
=> args; // Linux doesn't need the "--" prefix
510

@@ -11,8 +16,6 @@ public override ProcessStartInfo OpenFileWithApp(string filePath, string applica
1116
return new ProcessStartInfo(applicationPath, filePath);
1217
}
1318

14-
public override string RelativeEditorPathToExecutable => "Editor/Unity";
15-
1619
public override string UnityHubConfigDirectory => Path.Combine(UserHome, ".config/UnityHub");
1720

1821
public override ProcessStartInfo GetUnityProjectSearchProcess()

src/ucll/Shared/Platform/MacSupport.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ public override ProcessStartInfo OpenFileWithApp(string filePath, string applica
88
return new ProcessStartInfo("open", $"-a \"{applicationPath}\" \"{filePath}\"");
99
}
1010

11-
public override string RelativeEditorPathToExecutable => "Contents/MacOS/Unity";
11+
public override string FindInstallationRoot(string editorPath)
12+
{
13+
return editorPath.Replace("/Unity.app/Contents/MacOS/Unity", string.Empty);
14+
}
15+
16+
public override string GetUnityExecutablePath(string path)
17+
{
18+
return Path.Combine(path, "Contents/MacOS/Unity");
19+
}
1220

1321
public override string UnityHubConfigDirectory => Path.Combine(UserHome, "Library/Application Support/UnityHub");
1422

src/ucll/Shared/Platform/PlatformSupport.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public static PlatformSupport Create()
3434
/// <summary>
3535
/// Given the path to an editor executable, returns the root directory path of the installation.
3636
/// </summary>
37-
public string FindInstallationRoot(string editorPath)
38-
=> new DirectoryInfo(editorPath.Replace(RelativeEditorPathToExecutable, string.Empty)).Parent!.FullName;
37+
public abstract string FindInstallationRoot(string editorPath);
3938

4039
/// <summary>
4140
/// Path to the Unity Hub executable or null if it doesn't exist (or couldn't be found).
@@ -69,9 +68,9 @@ public string FindInstallationRoot(string editorPath)
6968
public abstract ProcessStartInfo OpenFileWithApp(string filePath, string applicationPath);
7069

7170
/// <summary>
72-
/// The path from the installation bundle (macOS) or root (Windows) to the executable.
71+
/// Converts an installation bundle path (macOS) to a path to the binary, if needed.
7372
/// </summary>
74-
public abstract string RelativeEditorPathToExecutable { get; }
73+
public virtual string GetUnityExecutablePath(string path) => path;
7574

7675
/// <summary>
7776
/// The path to the directory that contains Unity Hub config files.

src/ucll/Shared/Platform/WindowsSupport.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ public override ProcessStartInfo OpenFileWithApp(string filePath, string applica
1212
return new ProcessStartInfo(applicationPath, $"\"{filePath}\"");
1313
}
1414

15-
public override string RelativeEditorPathToExecutable => @"Editor\Unity.exe";
15+
public override string FindInstallationRoot(string editorPath)
16+
{
17+
return editorPath.Replace(@"Editor\Unity.exe", string.Empty).TrimEnd('\\');
18+
}
1619

1720
public override string UnityHubConfigDirectory =>
1821
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "UnityHub");

src/ucll/Shared/UnityHub.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@ internal class UnityHub(PlatformSupport platformSupport)
2323
public string GetEditorPath(string version)
2424
{
2525
// Fast: try the default install location first.
26-
string? executablePath = platformSupport.FindDefaultEditorPath(version);
27-
if (executablePath != null)
28-
return executablePath;
26+
string? editorPathDefault = platformSupport.FindDefaultEditorPath(version);
27+
if (editorPathDefault != null)
28+
return editorPathDefault;
2929

3030
// Fallback: query Unity Hub for custom installation locations.
3131
var editors = ListInstalledEditors();
32-
string? appBundlePath = editors.FirstOrDefault(p => p.Version == version).Path;
32+
string? editorPathHub = editors.FirstOrDefault(p => p.Version == version).Path;
3333

34-
if (appBundlePath == null)
34+
if (editorPathHub == null)
3535
throw new UserException($"Unity version {version} is not installed.");
3636

37-
return Path.Combine(appBundlePath, platformSupport.RelativeEditorPathToExecutable);
37+
// On macOS, the Unity Hub returns a path to the app bundle (Unity.app), but we need the binary within.
38+
return platformSupport.GetUnityExecutablePath(editorPathHub);
3839
}
3940

4041
public IEnumerable<string> GetRecentProjects(bool favoriteOnly = false)

src/ucll/ucll.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,4 @@
4040
<ItemGroup>
4141
<InternalsVisibleTo Include="ucll.Tests" />
4242
</ItemGroup>
43-
44-
<ItemGroup>
45-
<None Include="../../README.md" Pack="true" PackagePath="\" />
46-
</ItemGroup>
4743
</Project>

0 commit comments

Comments
 (0)