Skip to content

Commit d392b2d

Browse files
committed
Unpackaged support
1 parent 9ee0af6 commit d392b2d

File tree

5 files changed

+167
-156
lines changed

5 files changed

+167
-156
lines changed

KinectHandler/KinectHandler.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
</ItemGroup>
9696
<ItemGroup>
9797
<PackageReference Include="Amethyst.Plugins.Contract">
98-
<Version>0.3.33</Version>
98+
<Version>0.3.35</Version>
9999
</PackageReference>
100100
<PackageReference Include="System.ComponentModel">
101101
<Version>4.3.0</Version>

plugin_Kinect360/Fixes/NotReadyFix.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,12 @@ private async Task<bool> InstallDrivers(IProgress<InstallationProgress> progress
162162
progress.Report(new InstallationProgress
163163
{ IsIndeterminate = true, StageTitle = Host.RequestLocalizedString("/Plugins/Kinect360/Fixes/NotReady/Stage/InstallingDrivers") });
164164

165+
await PathsHandler.Setup();
166+
165167
var pathToDriversDirectory = Path.Join(Directory.GetParent(
166168
Assembly.GetExecutingAssembly().Location)!.FullName, "Assets", "Resources", "Dependencies", "Drivers");
167169

168-
var driverTemp = (await ApplicationData.Current.TemporaryFolder.CreateFolderAsync(
170+
var driverTemp = (await PathsHandler.TemporaryFolder.CreateFolderAsync(
169171
"Drivers", CreationCollisionOption.OpenIfExists)).Path;
170172

171173
try

plugin_Kinect360/PackageUtils.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,25 @@
44
using Windows.ApplicationModel;
55
using Windows.Storage;
66
using Amethyst.Plugins.Contract;
7+
using System.Reflection;
8+
using System.Threading.Tasks;
79

810
namespace plugin_Kinect360;
911

10-
public static class PackageUtils
12+
public static class PathsHandler
1113
{
14+
public static async Task Setup()
15+
{
16+
if (IsAmethystPackaged) return;
17+
18+
var root = await StorageFolder.GetFolderFromPathAsync(
19+
Path.Join(ProgramLocation.DirectoryName!));
20+
21+
TemporaryFolderUnpackaged = await (await root
22+
.CreateFolderAsync("AppData", CreationCollisionOption.OpenIfExists))
23+
.CreateFolderAsync("TempState", CreationCollisionOption.OpenIfExists);
24+
}
25+
1226
public static bool IsAmethystPackaged
1327
{
1428
get
@@ -24,15 +38,11 @@ public static bool IsAmethystPackaged
2438
}
2539
}
2640

27-
public static string GetAmethystAppDataPath()
28-
{
29-
return ApplicationData.Current.LocalFolder.Path;
30-
}
41+
public static FileInfo ProgramLocation => new(Assembly.GetExecutingAssembly().Location);
3142

32-
public static string GetAmethystTempPath()
33-
{
34-
return ApplicationData.Current.TemporaryFolder.Path;
35-
}
43+
public static StorageFolder TemporaryFolder => IsAmethystPackaged ? ApplicationData.Current.TemporaryFolder : TemporaryFolderUnpackaged;
44+
45+
public static StorageFolder TemporaryFolderUnpackaged { get; set; } // Assigned on Setup()
3646
}
3747

3848
public static class StorageExtensions

plugin_Kinect360/SdkInstaller.cs

Lines changed: 143 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ namespace plugin_Kinect360;
2222

2323
internal class SetupData : ICoreSetupData
2424
{
25-
public object PluginIcon => new PathIcon
26-
{
27-
Data = (Geometry)XamlBindingHelper.ConvertValue(typeof(Geometry),
28-
"M55.75,3.68a2.27,2.27,0,0,0-2.42-2.4c-8.5.05-17,0-25.5,0H2.38c-.22,0-.44,0-.66,0A1.84,1.84,0,0,0,0,3.12c0,2.4,0,4.81,0,7.21a2.06,2.06,0,0,0,.44,1.12,1.9,1.9,0,0,0,1.66.67H23.76c1.48,0,1.46,0,1.47,1.46,0,.38-.09.54-.52.61-2.79.46-5.57,1-8.35,1.43-.35.06-.47.21-.45.56,0,.64,0,1.28,0,1.92,0,.88.35,1.22,1.25,1.23H38.45c.9,0,1.24-.34,1.25-1.23,0-.64,0-1.28,0-1.92,0-.35-.1-.5-.45-.56L31.68,14.3c-1.28-.22-1.26-.22-1.3-1.51,0-.53.12-.7.68-.69,7.46,0,14.92,0,22.37,0a2.07,2.07,0,0,0,2.3-2.3C55.73,7.77,55.67,5.72,55.75,3.68ZM18.77,9a2.3,2.3,0,1,1,2.3-2.27A2.31,2.31,0,0,1,18.77,9ZM29.66,9a2.3,2.3,0,1,1,2.28-2.3A2.32,2.32,0,0,1,29.66,9ZM37.4,9a2.26,2.26,0,0,1-2.32-2.3,2.25,2.25,0,0,1,2.27-2.29,2.32,2.32,0,0,1,2.34,2.31A2.29,2.29,0,0,1,37.4,9Z")
29-
};
30-
31-
public string GroupName => "kinect";
32-
public Type PluginType => typeof(ITrackingDevice);
25+
public object PluginIcon => new PathIcon
26+
{
27+
Data = (Geometry)XamlBindingHelper.ConvertValue(typeof(Geometry),
28+
"M55.75,3.68a2.27,2.27,0,0,0-2.42-2.4c-8.5.05-17,0-25.5,0H2.38c-.22,0-.44,0-.66,0A1.84,1.84,0,0,0,0,3.12c0,2.4,0,4.81,0,7.21a2.06,2.06,0,0,0,.44,1.12,1.9,1.9,0,0,0,1.66.67H23.76c1.48,0,1.46,0,1.47,1.46,0,.38-.09.54-.52.61-2.79.46-5.57,1-8.35,1.43-.35.06-.47.21-.45.56,0,.64,0,1.28,0,1.92,0,.88.35,1.22,1.25,1.23H38.45c.9,0,1.24-.34,1.25-1.23,0-.64,0-1.28,0-1.92,0-.35-.1-.5-.45-.56L31.68,14.3c-1.28-.22-1.26-.22-1.3-1.51,0-.53.12-.7.68-.69,7.46,0,14.92,0,22.37,0a2.07,2.07,0,0,0,2.3-2.3C55.73,7.77,55.67,5.72,55.75,3.68ZM18.77,9a2.3,2.3,0,1,1,2.3-2.27A2.31,2.31,0,0,1,18.77,9ZM29.66,9a2.3,2.3,0,1,1,2.28-2.3A2.32,2.32,0,0,1,29.66,9ZM37.4,9a2.26,2.26,0,0,1-2.32-2.3,2.25,2.25,0,0,1,2.27-2.29,2.32,2.32,0,0,1,2.34,2.31A2.29,2.29,0,0,1,37.4,9Z")
29+
};
30+
31+
public string GroupName => "kinect";
32+
public Type PluginType => typeof(ITrackingDevice);
3333
}
3434

3535
internal class SdkInstaller : IDependencyInstaller
3636
{
37-
public IDependencyInstaller.ILocalizationHost Host { get; set; }
37+
public IDependencyInstaller.ILocalizationHost Host { get; set; }
3838

39-
public List<IDependency> ListDependencies()
40-
{
41-
return
39+
public List<IDependency> ListDependencies()
40+
{
41+
return
4242
[
4343
new KinectSdk
4444
{
@@ -47,157 +47,156 @@ public List<IDependency> ListDependencies()
4747
"Kinect for Xbox 360 SDK"
4848
}
4949
];
50-
}
50+
}
5151

52-
public List<IFix> ListFixes()
53-
{
54-
return
52+
public List<IFix> ListFixes()
53+
{
54+
return
5555
[
5656
new NotPoweredFix
5757
{
5858
Host = Host,
5959
Name = Host?.RequestLocalizedString( // Without the "fix" part
60-
"/Plugins/Kinect360/Fixes/NotPowered/Name") ?? "Not Powered"
60+
"/Plugins/Kinect360/Fixes/NotPowered/Name") ?? "Not Powered"
6161
},
6262
new NotReadyFix
6363
{
6464
Host = Host,
6565
Name = Host?.RequestLocalizedString( // Without the "fix" part
66-
"/Plugins/Kinect360/Fixes/NotReady/Name") ?? "Not Ready"
67-
},
66+
"/Plugins/Kinect360/Fixes/NotReady/Name") ?? "Not Ready"
67+
}
6868
];
69-
}
69+
}
7070
}
7171

7272
internal class KinectSdk : IDependency
7373
{
74-
private List<string> SdkFilesToInstall { get; } =
74+
private List<string> SdkFilesToInstall { get; } =
7575
[
7676
"KinectDrivers-v1.8-x64.WHQL.msi",
7777
"KinectRuntime-v1.8-x64.msi",
7878
"KinectSDK-v1.8-x64.msi"
7979
];
8080

81-
public IDependencyInstaller.ILocalizationHost Host { get; set; }
82-
83-
public string Name { get; set; }
84-
public bool IsMandatory => true;
85-
86-
public bool IsInstalled
87-
{
88-
get
89-
{
90-
try
91-
{
92-
// Well, this is pretty much all we need for the plugin to be loaded
93-
return File.Exists(@"C:\Windows\System32\Kinect10.dll");
94-
}
95-
catch (Exception)
96-
{
97-
// Access denied?
98-
return false;
99-
}
100-
}
101-
}
102-
103-
public string InstallerEula
104-
{
105-
get
106-
{
107-
try
108-
{
109-
return File.ReadAllText(Path.Join(
110-
Directory.GetParent(Assembly.GetExecutingAssembly().Location)!.FullName,
111-
"Assets", "Resources", "eula.md"));
112-
}
113-
catch (Exception)
114-
{
115-
return string.Empty;
116-
}
117-
}
118-
}
119-
120-
public async Task<bool> Install(IProgress<InstallationProgress> progress, CancellationToken cancellationToken)
121-
{
122-
// Amethyst will handle this exception for us anyway
123-
cancellationToken.ThrowIfCancellationRequested();
124-
var dependenciesFolder = Path.Join(Directory.GetParent(
125-
Assembly.GetExecutingAssembly().Location)!.FullName,
126-
"Assets", "Resources", "Dependencies");
127-
128-
// Copy to temp if amethyst is packaged
129-
// ReSharper disable once InvertIf
130-
if (PackageUtils.IsAmethystPackaged)
131-
{
132-
// Create a shared folder with the dependencies
133-
var dependenciesFolderInternal = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync(
134-
Guid.NewGuid().ToString().ToUpper(), CreationCollisionOption.OpenIfExists);
135-
136-
// Copy all driver files to Amethyst's local data folder
137-
new DirectoryInfo(Path.Join(Directory.GetParent(Assembly.GetExecutingAssembly().Location)!.FullName,
138-
"Assets", "Resources", "Dependencies"))
139-
.CopyToFolder(dependenciesFolderInternal.Path);
140-
141-
// Update the installation paths
142-
dependenciesFolder = dependenciesFolderInternal.Path;
143-
}
144-
145-
// Finally install the packages
146-
return InstallFiles(SdkFilesToInstall.Select(x => Path.Join(
147-
dependenciesFolder, x)), progress, cancellationToken);
148-
149-
// Apply other related fixes, non-critical
150-
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
151-
// (await SetupPost(progress) || true); // TODO
152-
}
153-
154-
private bool InstallFiles(IEnumerable<string> files,
155-
IProgress<InstallationProgress> progress, CancellationToken cancellationToken)
156-
{
157-
// Amethyst will handle this exception for us anyway
158-
cancellationToken.ThrowIfCancellationRequested();
159-
160-
// Execute each install
161-
foreach (var installFile in files)
162-
try
163-
{
164-
// msi /qn /norestart
165-
progress.Report(new InstallationProgress
166-
{
167-
IsIndeterminate = true,
168-
StageTitle =
169-
(Host?.RequestLocalizedString("/Plugins/Kinect360/Stages/Installing") ??
170-
"Installing {0}...").Replace("{0}", Path.GetFileName(installFile))
171-
});
172-
173-
var msiExecutableStart = new ProcessStartInfo
174-
{
175-
FileName = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
176-
@"System32\msiexec.exe"),
177-
WorkingDirectory = Directory.GetParent(installFile)!.FullName,
178-
Arguments = $"/i {installFile} /quiet /qn /norestart ALLUSERS=1",
179-
CreateNoWindow = true,
180-
WindowStyle = ProcessWindowStyle.Hidden,
181-
UseShellExecute = true,
182-
Verb = "runas"
183-
};
184-
185-
var msiExecutable = Process.Start(msiExecutableStart);
186-
msiExecutable!.WaitForExit(60000);
187-
}
188-
catch (Exception e)
189-
{
190-
progress.Report(new InstallationProgress
191-
{
192-
IsIndeterminate = true,
193-
StageTitle =
194-
(Host?.RequestLocalizedString("/Plugins/Kinect360/Stages/Exceptions/Other") ??
195-
"Exception: {0}").Replace("{0}", e.Message)
196-
});
197-
198-
return false;
199-
}
200-
201-
return true;
202-
}
203-
}
81+
public IDependencyInstaller.ILocalizationHost Host { get; set; }
82+
83+
public string Name { get; set; }
84+
public bool IsMandatory => true;
85+
86+
public bool IsInstalled
87+
{
88+
get
89+
{
90+
try
91+
{
92+
// Well, this is pretty much all we need for the plugin to be loaded
93+
return File.Exists(@"C:\Windows\System32\Kinect10.dll");
94+
}
95+
catch (Exception)
96+
{
97+
// Access denied?
98+
return false;
99+
}
100+
}
101+
}
102+
103+
public string InstallerEula
104+
{
105+
get
106+
{
107+
try
108+
{
109+
return File.ReadAllText(Path.Join(
110+
Directory.GetParent(Assembly.GetExecutingAssembly().Location)!.FullName,
111+
"Assets", "Resources", "eula.md"));
112+
}
113+
catch (Exception)
114+
{
115+
return string.Empty;
116+
}
117+
}
118+
}
119+
120+
public async Task<bool> Install(IProgress<InstallationProgress> progress, CancellationToken cancellationToken)
121+
{
122+
// Amethyst will handle this exception for us anyway
123+
cancellationToken.ThrowIfCancellationRequested();
124+
var dependenciesFolder = Path.Join(Directory.GetParent(
125+
Assembly.GetExecutingAssembly().Location)!.FullName,
126+
"Assets", "Resources", "Dependencies");
127+
128+
await PathsHandler.Setup();
129+
130+
// Copy to temp if amethyst is packaged
131+
// ReSharper disable once InvertIf
132+
// Create a shared folder with the dependencies
133+
var dependenciesFolderInternal = await PathsHandler.TemporaryFolder.CreateFolderAsync(
134+
Guid.NewGuid().ToString().ToUpper(), CreationCollisionOption.OpenIfExists);
135+
136+
// Copy all driver files to Amethyst's local data folder
137+
new DirectoryInfo(Path.Join(Directory.GetParent(Assembly.GetExecutingAssembly().Location)!.FullName,
138+
"Assets", "Resources", "Dependencies"))
139+
.CopyToFolder(dependenciesFolderInternal.Path);
140+
141+
// Update the installation paths
142+
dependenciesFolder = dependenciesFolderInternal.Path;
143+
144+
// Finally install the packages
145+
return InstallFiles(SdkFilesToInstall.Select(x => Path.Join(
146+
dependenciesFolder, x)), progress, cancellationToken);
147+
148+
// Apply other related fixes, non-critical
149+
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
150+
// (await SetupPost(progress) || true); // TODO
151+
}
152+
153+
private bool InstallFiles(IEnumerable<string> files,
154+
IProgress<InstallationProgress> progress, CancellationToken cancellationToken)
155+
{
156+
// Amethyst will handle this exception for us anyway
157+
cancellationToken.ThrowIfCancellationRequested();
158+
159+
// Execute each install
160+
foreach (var installFile in files)
161+
try
162+
{
163+
// msi /qn /norestart
164+
progress.Report(new InstallationProgress
165+
{
166+
IsIndeterminate = true,
167+
StageTitle =
168+
(Host?.RequestLocalizedString("/Plugins/Kinect360/Stages/Installing") ??
169+
"Installing {0}...").Replace("{0}", Path.GetFileName(installFile))
170+
});
171+
172+
var msiExecutableStart = new ProcessStartInfo
173+
{
174+
FileName = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
175+
@"System32\msiexec.exe"),
176+
WorkingDirectory = Directory.GetParent(installFile)!.FullName,
177+
Arguments = $"/i {installFile} /quiet /qn /norestart ALLUSERS=1",
178+
CreateNoWindow = true,
179+
WindowStyle = ProcessWindowStyle.Hidden,
180+
UseShellExecute = true,
181+
Verb = "runas"
182+
};
183+
184+
var msiExecutable = Process.Start(msiExecutableStart);
185+
msiExecutable!.WaitForExit(60000);
186+
}
187+
catch (Exception e)
188+
{
189+
progress.Report(new InstallationProgress
190+
{
191+
IsIndeterminate = true,
192+
StageTitle =
193+
(Host?.RequestLocalizedString("/Plugins/Kinect360/Stages/Exceptions/Other") ??
194+
"Exception: {0}").Replace("{0}", e.Message)
195+
});
196+
197+
return false;
198+
}
199+
200+
return true;
201+
}
202+
}

0 commit comments

Comments
 (0)