Skip to content

Commit 3be2903

Browse files
Remove Unused Code
1 parent ab783ef commit 3be2903

File tree

4 files changed

+54
-160
lines changed

4 files changed

+54
-160
lines changed

src/CommunityToolkit.Maui.MediaElement/Extensions/AppInfoUtils.windows.cs

Lines changed: 0 additions & 95 deletions
This file was deleted.

src/CommunityToolkit.Maui.MediaElement/Extensions/FileSystemUtils.windows.cs

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Windows.ApplicationModel;
2+
3+
namespace CommunityToolkit.Maui.Extensions;
4+
5+
// Since MediaElement can't access .NET MAUI internals we have to copy this code here
6+
// https://github.com/dotnet/maui/blob/main/src/Essentials/src/AppInfo/AppInfo.uwp.cs
7+
static class AppPackageService
8+
{
9+
static readonly Lazy<bool> isPackagedAppHolder = new(() =>
10+
{
11+
try
12+
{
13+
if (Package.Current is not null)
14+
{
15+
return true;
16+
}
17+
}
18+
catch
19+
{
20+
// no-op
21+
}
22+
23+
return false;
24+
});
25+
26+
static readonly Lazy<string> fullAppPackageFilePathHolder = new(() =>
27+
{
28+
return IsPackagedApp
29+
? Package.Current.InstalledLocation.Path
30+
: AppContext.BaseDirectory;
31+
});
32+
33+
/// <summary>
34+
/// Gets if this app is a packaged app.
35+
/// </summary>
36+
public static bool IsPackagedApp => isPackagedAppHolder.Value;
37+
38+
39+
/// <summary>
40+
/// Gets full application path.
41+
/// </summary>
42+
public static string FullAppPackageFilePath => fullAppPackageFilePathHolder.Value;
43+
}

src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ protected virtual async partial ValueTask PlatformUpdateSource()
308308
return;
309309
}
310310

311-
// To test this run app as unpackaged and packaged.
312-
string path = FileSystemUtils.PlatformGetFullAppPackageFilePath(resourceMediaSource.Path);
311+
string path = GetFullAppPackageFilePath(resourceMediaSource.Path);
313312
if (!string.IsNullOrWhiteSpace(path))
314313
{
315314
Player.Source = WinMediaSource.CreateFromUri(new Uri(path));
@@ -360,6 +359,16 @@ protected virtual void Dispose(bool disposing)
360359
}
361360
}
362361

362+
static string GetFullAppPackageFilePath(in string filename)
363+
{
364+
ArgumentNullException.ThrowIfNull(filename);
365+
366+
var normalizedFilename = NormalizePath(filename);
367+
return Path.Combine(AppPackageService.FullAppPackageFilePath, normalizedFilename);
368+
369+
static string NormalizePath(string filename) => filename.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar);
370+
}
371+
363372
static bool IsZero<TValue>(TValue numericValue) where TValue : INumber<TValue>
364373
{
365374
return TValue.IsZero(numericValue);

0 commit comments

Comments
 (0)