Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit fc0cbdd

Browse files
Merge pull request #44 from github-for-unity/fixes/loading-resources
Loading resources was horribly horribly broken
2 parents c0b4bb4 + dd2d932 commit fc0cbdd

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public ITask InitializeRepository()
107107
.Then(GitClient.LfsInstall())
108108
.ThenInUI(SetProjectToTextSerialization)
109109
.Then(new ActionTask(CancellationToken, _ => {
110-
AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath);
111-
AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath);
110+
AssemblyResources.ToFile(ResourceType.Generic, ".gitignore", targetPath, Environment);
111+
AssemblyResources.ToFile(ResourceType.Generic, ".gitattributes", targetPath, Environment);
112112

113113
assetsGitignore.CreateFile();
114114
}))

src/GitHub.Api/Helpers/AssemblyResources.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ enum ResourceType
1212

1313
class AssemblyResources
1414
{
15-
public static NPath ToFile(ResourceType resourceType, string resource, NPath destinationPath)
15+
public static NPath ToFile(ResourceType resourceType, string resource, NPath destinationPath, IEnvironment environment)
1616
{
1717
var os = "";
1818
if (resourceType == ResourceType.Platform)
@@ -21,15 +21,15 @@ public static NPath ToFile(ResourceType resourceType, string resource, NPath des
2121
: DefaultEnvironment.OnLinux ? "linux"
2222
: "mac";
2323
}
24-
var type = resourceType == ResourceType.Icon ? "Icons"
24+
var type = resourceType == ResourceType.Icon ? "IconsAndLogos"
2525
: resourceType == ResourceType.Platform ? "PlatformResources"
2626
: "Resources";
2727
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
2828
String.Format("GitHub.Unity.{0}{1}.{2}", type, os != "" ? "." + os : os, resource));
2929
if (stream != null)
3030
return destinationPath.Combine(resource).WriteAllBytes(stream.ToByteArray());
3131

32-
return new NPath(type).Combine(os, resource);
32+
return environment.ExtensionInstallPath.Combine(type, os, resource);
3333
}
3434
}
3535
}

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public Task<bool> SetupGitIfNeeded(NPath tempPath, IProgress<float> zipFileProgr
163163

164164
cancellationToken.ThrowIfCancellationRequested();
165165

166-
var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, GitZipFile, tempPath);
166+
var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, GitZipFile, tempPath, environment);
167167
if (!archiveFilePath.FileExists())
168168
{
169169
logger.Warning("Archive \"{0}\" missing", archiveFilePath.ToString());
@@ -228,7 +228,7 @@ public Task<bool> SetupGitLfsIfNeeded(NPath tempPath, IProgress<float> zipFilePr
228228

229229
cancellationToken.ThrowIfCancellationRequested();
230230

231-
var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, GitLfsZipFile, tempPath);
231+
var archiveFilePath = AssemblyResources.ToFile(ResourceType.Platform, GitLfsZipFile, tempPath, environment);
232232
if (!archiveFilePath.FileExists())
233233
{
234234
logger.Warning("Archive \"{0}\" missing", archiveFilePath.ToString());

src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public IEnvironment Environment
5050
{
5151
unityAssetsPath = Application.dataPath;
5252
unityApplication = EditorApplication.applicationPath;
53-
extensionInstallPath = AssetDatabase.GetAssetPath(this);
53+
extensionInstallPath = DetermineInstallationPath();
5454
unityVersion = Application.unityVersion;
5555
}
5656
environment.Initialize(unityVersion, extensionInstallPath.ToNPath(), unityApplication.ToNPath(), unityAssetsPath.ToNPath());
@@ -62,6 +62,16 @@ public IEnvironment Environment
6262
}
6363
}
6464

65+
private NPath DetermineInstallationPath()
66+
{
67+
// Juggling to find out where we got installed
68+
var shim = ScriptableObject.CreateInstance<RunLocationShim>();
69+
var script = MonoScript.FromScriptableObject(shim);
70+
var scriptPath = AssetDatabase.GetAssetPath(script).ToNPath();
71+
ScriptableObject.DestroyImmediate(shim);
72+
return scriptPath.Parent;
73+
}
74+
6575
public void Flush()
6676
{
6777
repositoryPath = Environment.RepositoryPath;

0 commit comments

Comments
 (0)