Skip to content

Commit 0052d74

Browse files
committed
Msiexec installer fix?
1 parent b2bbc78 commit 0052d74

2 files changed

Lines changed: 74 additions & 4 deletions

File tree

plugin_KinectOne/PackageUtils.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.IO;
3+
using Windows.ApplicationModel;
4+
using Windows.Storage;
5+
6+
namespace plugin_KinectOne;
7+
8+
public static class PackageUtils
9+
{
10+
public static bool IsAmethystPackaged
11+
{
12+
get
13+
{
14+
try
15+
{
16+
return Package.Current is not null;
17+
}
18+
catch (Exception)
19+
{
20+
return false;
21+
}
22+
}
23+
}
24+
25+
public static string GetAmethystAppDataPath()
26+
{
27+
return ApplicationData.Current.LocalFolder.Path;
28+
}
29+
30+
public static string GetAmethystTempPath()
31+
{
32+
return ApplicationData.Current.TemporaryFolder.Path;
33+
}
34+
}
35+
36+
public static class StorageExtensions
37+
{
38+
public static void CopyToFolder(this DirectoryInfo source, string destination, bool log = false)
39+
{
40+
// Now Create all of the directories
41+
foreach (var dirPath in source.GetDirectories("*", SearchOption.AllDirectories))
42+
Directory.CreateDirectory(dirPath.FullName.Replace(source.FullName, destination));
43+
44+
// Copy all the files & Replaces any files with the same name
45+
foreach (var newPath in source.GetFiles("*.*", SearchOption.AllDirectories))
46+
newPath.CopyTo(newPath.FullName.Replace(source.FullName, destination), true);
47+
}
48+
}

plugin_KinectOne/RuntimeInstaller.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,38 @@ public string InstallerEula
8888
}
8989
}
9090

91-
public Task<bool> Install(IProgress<InstallationProgress> progress, CancellationToken cancellationToken)
91+
public async Task<bool> Install(IProgress<InstallationProgress> progress, CancellationToken cancellationToken)
9292
{
9393
// Amethyst will handle this exception for us anyway
9494
cancellationToken.ThrowIfCancellationRequested();
95-
96-
return Task.FromResult(InstallFiles(new[]
95+
var paths = new[]
9796
{
9897
Path.Join(Directory.GetParent(Assembly.GetExecutingAssembly().Location)!.FullName,
9998
"Assets", "Resources", "Dependencies", "KinectRuntime-x64.msi")
100-
}, progress, cancellationToken));
99+
};
100+
101+
// Copy to temp if amethyst is packaged
102+
// ReSharper disable once InvertIf
103+
if (PackageUtils.IsAmethystPackaged)
104+
{
105+
// Create a shared folder with the dependencies
106+
var dependenciesFolder = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync(
107+
Guid.NewGuid().ToString().ToUpper(), CreationCollisionOption.OpenIfExists);
108+
109+
// Copy all driver files to Amethyst's local data folder
110+
new DirectoryInfo(Path.Join(Directory.GetParent(Assembly.GetExecutingAssembly().Location)!.FullName,
111+
"Assets", "Resources", "Dependencies"))
112+
.CopyToFolder(dependenciesFolder.Path);
113+
114+
// Update the installation paths
115+
paths = new[]
116+
{
117+
Path.Join(dependenciesFolder.Path, "KinectRuntime-x64.msi")
118+
};
119+
}
120+
121+
// Finally install the packages
122+
return InstallFiles(paths, progress, cancellationToken);
101123
}
102124

103125
private bool InstallFiles(IEnumerable<string> files,

0 commit comments

Comments
 (0)