Update to Strix Music 0.1.0 alpha

This commit is contained in:
Yoshi Askharoun
2023-05-03 14:04:00 -05:00
parent 5befeb7b35
commit 86a7612772
12 changed files with 813 additions and 435 deletions
+1 -2
View File
@@ -33,8 +33,7 @@
</ItemGroup>
<ItemGroup Condition="$(UseOpenZune)">
<PackageReference Include="StrixMusic.Sdk" Version="0.0.12-alpha" />
<PackageReference Include="StrixMusic.Cores.LocalFiles" Version="0.0.12-alpha" />
<PackageReference Include="StrixMusic.Sdk" Version="0.1.0-alpha" />
<PackageReference Include="LibVLCSharp" Version="3.6.6" />
@@ -28,7 +28,7 @@ using System.Linq;
#if OPENZUNE
using Microsoft.Zune.Playback;
using OwlCore.Events;
using OwlCore.ComponentModel;
using StrixMusic.Sdk.AdapterModels;
using StrixMusic.Sdk.AppModels;
using StrixMusic.Sdk.CoreModels;
@@ -161,22 +161,14 @@ namespace Microsoft.Zune.Shell
CultureHelper.CheckValidRegionAndLanguage();
#if OPENZUNE
string id = Guid.NewGuid().ToString();
DirectoryInfo cacheFolderPath = new(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\Zune\OpenZune\LocalCoreCache"));
cacheFolderPath.Create();
OwlCore.Storage.SystemIO.SystemFolder cacheFolder = new(cacheFolderPath);
var fileService = new OwlCore.AbstractStorage.Win32FileSystemService(@"D:\Music\Zune\Test");
OwlCore.AbstractStorage.SystemIOFolderData settingsFolder =
new(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Microsoft\Zune\OpenZune"));
settingsFolder.EnsureExists().Wait();
StrixMusic.Cores.LocalFiles.Settings.LocalFilesCoreSettings settings = new(settingsFolder)
OwlCore.Storage.SystemIO.SystemFolder musicFolder = new(@"D:\Music\Zune\Test");
var localCore = new StrixMusic.Cores.Storage.StorageCore(musicFolder, cacheFolder, "Local Test")
{
InitWithEmptyMetadataRepos = true,
ScanWithTagLib = true,
};
var localCore = new StrixMusic.Cores.LocalFiles.LocalFilesCore(
id, settings, fileService, null, null)
{
ScannerWaitBehavior = StrixMusic.Cores.Files.ScannerWaitBehavior.AlwaysWait
ScannerWaitBehavior = StrixMusic.Cores.Storage.ScannerWaitBehavior.AlwaysWait,
};
var prefs = new MergedCollectionConfig
@@ -1,32 +0,0 @@
#if OPENZUNE
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace OwlCore.AbstractStorage
{
/// <inheritdoc />
public class FileDataProperties : IFileDataProperties
{
private readonly FileInfo _file;
/// <summary>
/// Initializes a new instance of the <see cref="FileDataProperties"/> class.
/// </summary>
/// <param name="file">The file to get properties from.</param>
public FileDataProperties(FileInfo file)
{
_file = file;
}
/// <inheritdoc />
public async Task<MusicFileProperties?> GetMusicPropertiesAsync()
{
throw new NotImplementedException();
}
}
}
#endif
@@ -1,71 +0,0 @@
#if OPENZUNE
// Copyright (c) Arlo Godfrey. All Rights Reserved.
// Licensed under the GNU Lesser General Public License, Version 3.0 with additional terms.
// See the LICENSE, LICENSE.LESSER and LICENSE.ADDITIONAL files in the project root for more information.
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using OwlCore.Extensions;
namespace OwlCore.Services
{
/// <summary>
/// An <see cref="IAsyncSerializer{TSerialized}"/> and implementation for serializing and deserializing streams using System.Text.Json.
/// </summary>
public class NewtonsoftStreamSerializer : IAsyncSerializer<Stream>, ISerializer<Stream>
{
/// <summary>
/// A singleton instance for <see cref="NewtonsoftStreamSerializer"/>.
/// </summary>
public static NewtonsoftStreamSerializer Singleton { get; } = new();
/// <inheritdoc />
public Task<Stream> SerializeAsync<T>(T data, CancellationToken? cancellationToken = null) => Task.Run(() => Serialize(data), cancellationToken ?? CancellationToken.None);
/// <inheritdoc />
public Task<Stream> SerializeAsync(Type inputType, object data, CancellationToken? cancellationToken = null) => Task.Run(() => Serialize(inputType, data), cancellationToken ?? CancellationToken.None);
/// <inheritdoc />
public Task<TResult> DeserializeAsync<TResult>(Stream serialized, CancellationToken? cancellationToken = null) => Task.Run(() => Deserialize<TResult>(serialized), cancellationToken ?? CancellationToken.None);
/// <inheritdoc />
public Task<object> DeserializeAsync(Type returnType, Stream serialized, CancellationToken? cancellationToken = null) => Task.Run(() => Deserialize(returnType, serialized), cancellationToken ?? CancellationToken.None);
/// <inheritdoc />
public Stream Serialize<T>(T data)
{
var res = JsonConvert.SerializeObject(data, typeof(T), null);
return new MemoryStream(Encoding.UTF8.GetBytes(res));
}
/// <inheritdoc />
public Stream Serialize(Type type, object data)
{
var res = JsonConvert.SerializeObject(data, type, null);
return new MemoryStream(Encoding.UTF8.GetBytes(res));
}
/// <inheritdoc />
public TResult Deserialize<TResult>(Stream serialized)
{
serialized.Position = 0;
var str = Encoding.UTF8.GetString(serialized.ToBytes());
return (TResult)JsonConvert.DeserializeObject(str, typeof(TResult))!;
}
/// <inheritdoc />
public object Deserialize(Type type, Stream serialized)
{
serialized.Position = 0;
var str = Encoding.UTF8.GetString(serialized.ToBytes());
return JsonConvert.DeserializeObject(str, type)!;
}
}
}
#endif
@@ -1,89 +0,0 @@
#if OPENZUNE
using System;
using System.IO;
using System.Threading.Tasks;
namespace OwlCore.AbstractStorage
{
/// <inheritdoc cref="IFileData"/>
public class SystemIOFileData : IFileData
{
/// <summary>
/// The underlying <see cref="File"/> instance in use.
/// </summary>
internal FileInfo File { get; }
/// <summary>
/// Creates a new instance of <see cref="SystemIOFileData" />.
/// </summary>
/// <param name="file">The <see cref="FileInfo"/> to wrap.</param>
public SystemIOFileData(FileInfo file)
{
File = file;
Properties = new FileDataProperties(file);
}
/// <summary>
/// Creates a new instance of <see cref="SystemIOFileData" />.
/// </summary>
/// <param name="file">The path of the file to wrap.</param>
public SystemIOFileData(string filePath) : this(new FileInfo(filePath))
{
}
/// <inheritdoc/>
public string Path => File.FullName;
/// <inheritdoc/>
public string Name => File.Name;
/// <inheritdoc/>
public string DisplayName => File.Name;
/// <inheritdoc/>
public string FileExtension => File.Extension;
/// <inheritdoc/>
public string Id => Extensions.StringExtensions.HashMD5Fast(Path);
/// <inheritdoc/>
public IFileDataProperties Properties { get; set; }
/// <inheritdoc/>
public Task<IFolderData> GetParentAsync()
{
return Task.FromResult<IFolderData>(new SystemIOFolderData(File.Directory));
}
/// <inheritdoc/>
public Task Delete()
{
return Task.Run(File.Delete);
}
/// <inheritdoc />
public Task<Stream> GetStreamAsync(FileAccessMode accessMode = FileAccessMode.Read)
{
return Task.Run<Stream>(() => File.Open(
FileMode.Open,
accessMode == FileAccessMode.ReadWrite ? FileAccess.ReadWrite : FileAccess.Read));
}
/// <inheritdoc />
public Task WriteAllBytesAsync(byte[] bytes)
{
return System.IO.File.WriteAllBytesAsync(File.FullName, bytes);
}
/// <inheritdoc />
public async Task<Stream> GetThumbnailAsync(ThumbnailMode thumbnailMode, uint requiredSize)
{
throw new NotImplementedException();
}
}
}
#endif
@@ -1,167 +0,0 @@
#if OPENZUNE
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace OwlCore.AbstractStorage
{
/// <summary>
/// Represents a folder backed by <c>System.IO</c>.
/// </summary>
public class SystemIOFolderData : IFolderData
{
/// <summary>
/// The underlying <see cref="DirectoryInfo"/> instance in use.
/// </summary>
public DirectoryInfo Directory { get; private set; }
/// <summary>
/// Constructs a new instance of <see cref="IFolderData"/>.
/// </summary>
public SystemIOFolderData(DirectoryInfo folder)
{
Directory = folder;
}
/// <summary>
/// Constructs a new instance of <see cref="IFolderData"/>.
/// </summary>
public SystemIOFolderData(string folderPath) : this(new DirectoryInfo(folderPath))
{
}
/// <inheritdoc/>
public string Name => Directory.Name;
/// <inheritdoc/>
public string Path => Directory.FullName;
/// <inheritdoc/>
public string Id => Extensions.StringExtensions.HashMD5Fast(Path);
/// <inheritdoc/>
public Task<IEnumerable<IFileData>> GetFilesAsync()
{
return Task.Run<IEnumerable<IFileData>>(() => Directory.GetFiles().Select(x => new SystemIOFileData(x)));
}
/// <inheritdoc />
public Task DeleteAsync() => Task.Run(Directory.Delete);
/// <inheritdoc/>
public Task<IFolderData> GetParentAsync()
{
return Task.FromResult<IFolderData>(new SystemIOFolderData(Directory.Parent));
}
/// <inheritdoc/>
public Task<IFolderData> CreateFolderAsync(string desiredName)
{
return Task.Run<IFolderData>(() => new SystemIOFolderData(Directory.CreateSubdirectory(desiredName)));
}
/// <inheritdoc/>
public async Task<IFolderData> CreateFolderAsync(string desiredName, CreationCollisionOption options)
{
if (options == CreationCollisionOption.OpenIfExists)
{
SystemIOFolderData folder = new(System.IO.Path.Combine(Path, desiredName));
await folder.EnsureExists();
return folder;
}
else if (options == CreationCollisionOption.FailIfExists)
{
throw new NotImplementedException();
}
return await CreateFolderAsync(desiredName);
}
/// <inheritdoc/>
public Task<IFileData> CreateFileAsync(string desiredName)
{
return Task.Run<IFileData>(delegate
{
SystemIOFileData file = new(System.IO.Path.Combine(Path, desiredName));
file.File.Create().Dispose();
return file;
});
}
/// <inheritdoc/>
public Task<IFileData> CreateFileAsync(string desiredName, CreationCollisionOption options)
{
return Task.Run<IFileData>(delegate
{
string name = desiredName;
FileMode mode = FileMode.CreateNew;
if (options == CreationCollisionOption.OpenIfExists)
{
mode = FileMode.OpenOrCreate;
}
else if (options == CreationCollisionOption.GenerateUniqueName)
{
string nameNoExt = System.IO.Path.GetFileNameWithoutExtension(name);
string ext = System.IO.Path.GetExtension(name);
int i = 0;
while (File.Exists(System.IO.Path.Combine(Path, name)))
{
name = $"{nameNoExt} ({++i}){ext}";
}
}
else if (options == CreationCollisionOption.ReplaceExisting)
{
mode = FileMode.Create;
}
SystemIOFileData file = new(System.IO.Path.Combine(Path, name));
file.File.Open(mode).Dispose();
return file;
});
}
/// <inheritdoc/>
public Task<IFolderData?> GetFolderAsync(string name)
{
return Task.Run<IFolderData?>(delegate
{
SystemIOFolderData folder = new(System.IO.Path.Combine(Path, name));
return folder.Directory.Exists ? folder : null;
});
}
/// <inheritdoc/>
public Task<IFileData?> GetFileAsync(string name)
{
return Task.Run<IFileData?>(delegate
{
SystemIOFileData file = new(System.IO.Path.Combine(Path, name));
return file.File.Exists ? file : null;
});
}
/// <inheritdoc/>
public Task<IEnumerable<IFolderData>> GetFoldersAsync()
{
return Task.Run<IEnumerable<IFolderData>>(() => Directory.GetDirectories().Select(x => new SystemIOFolderData(x)));
}
/// <inheritdoc />
public Task EnsureExists()
{
return Task.Run(delegate
{
if (Directory.Exists) return;
Directory.Create();
});
}
}
}
#endif
@@ -1,49 +0,0 @@
#if OPENZUNE
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace OwlCore.AbstractStorage;
public class Win32FileSystemService : IFileSystemService
{
public Win32FileSystemService(string rootFolder)
{
RootFolder = new SystemIOFolderData(rootFolder);
}
public IFolderData RootFolder { get; }
public bool IsInitialized => true;
public Task<IFolderData> CreateDirectoryAsync(string folderName)
=> RootFolder.CreateFolderAsync(folderName);
public Task<bool> DirectoryExistsAsync(string path) => Task.FromResult(Directory.Exists(path));
public Task<bool> FileExistsAsync(string path) => Task.FromResult(File.Exists(path));
public Task<IFileData> GetFileFromPathAsync(string path)
=> Task.FromResult<IFileData>(new SystemIOFileData(path));
public Task<IFolderData> GetFolderFromPathAsync(string path)
=> Task.FromResult<IFolderData>(new SystemIOFolderData(path));
public Task<IReadOnlyList<IFolderData>> GetPickedFolders()
{
throw new System.NotImplementedException();
}
public Task InitAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
public Task<IFolderData> PickFolder()
{
return Task.FromResult(RootFolder);
}
public Task RevokeAccess(IFolderData folder) => Task.CompletedTask;
}
#endif
+7 -2
View File
@@ -66,8 +66,13 @@
</ItemGroup>
<ItemGroup Condition=" $(UseOpenZune) ">
<!--<PackageReference Include="StrixMusic.Sdk" Version="0.0.3-alpha" /-->
<PackageReference Include="StrixMusic.Cores.LocalFiles" Version="0.0.12-alpha" />
<PackageReference Include="StrixMusic.Sdk" Version="0.1.0-alpha" />
<Reference Include="StrixMusic.Cores.Storage">
<HintPath>..\libs\nuget\StrixMusic.Cores.Storage\StrixMusic.Cores.Storage.dll</HintPath>
</Reference>
<Reference Include="OwlCore.Storage.OneDrive">
<HintPath>..\libs\nuget\OwlCore.Storage.OneDrive\OwlCore.Storage.OneDrive.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition=" !$(UseOpenZune) ">
@@ -0,0 +1,68 @@
<?xml version="1.0"?>
<doc>
<assembly>
<name>OwlCore.Storage.OneDrive</name>
</assembly>
<members>
<member name="T:OwlCore.Storage.OneDrive.OneDriveFile">
<summary>
A file implementation that interacts with a file in OneDrive.
</summary>
</member>
<member name="M:OwlCore.Storage.OneDrive.OneDriveFile.#ctor(Microsoft.Graph.GraphServiceClient,Microsoft.Graph.Models.DriveItem)">
<summary>
Creates a new instance of <see cref="T:OwlCore.Storage.OneDrive.OneDriveFile"/>.
</summary>
</member>
<member name="P:OwlCore.Storage.OneDrive.OneDriveFile.DriveItem">
<summary>
The graph item that was provided as the backing implementation for this file.
</summary>
</member>
<member name="P:OwlCore.Storage.OneDrive.OneDriveFile.Id">
<inheritdoc />
</member>
<member name="P:OwlCore.Storage.OneDrive.OneDriveFile.Name">
<inheritdoc />
</member>
<member name="M:OwlCore.Storage.OneDrive.OneDriveFile.GetParentAsync(System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:OwlCore.Storage.OneDrive.OneDriveFile.OpenStreamAsync(System.IO.FileAccess,System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="T:OwlCore.Storage.OneDrive.OneDriveFolder">
<summary>
A folder implementation that interacts with a folder in OneDrive.
</summary>
</member>
<member name="M:OwlCore.Storage.OneDrive.OneDriveFolder.#ctor(Microsoft.Graph.GraphServiceClient,Microsoft.Graph.Models.DriveItem)">
<summary>
Creates a new instance of <see cref="T:OwlCore.Storage.OneDrive.OneDriveFolder"/>.
</summary>
</member>
<member name="P:OwlCore.Storage.OneDrive.OneDriveFolder.Id">
<inheritdoc />
</member>
<member name="P:OwlCore.Storage.OneDrive.OneDriveFolder.Name">
<inheritdoc />
</member>
<member name="P:OwlCore.Storage.OneDrive.OneDriveFolder.DriveItem">
<summary>
The graph item that was provided as the backing implementation for this file.
</summary>
</member>
<member name="M:OwlCore.Storage.OneDrive.OneDriveFolder.GetItemsAsync(OwlCore.Storage.StorableType,System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:OwlCore.Storage.OneDrive.OneDriveFolder.GetItemRecursiveAsync(System.String,System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:OwlCore.Storage.OneDrive.OneDriveFolder.GetItemAsync(System.String,System.Threading.CancellationToken)">
<inheritdoc />
</member>
<member name="M:OwlCore.Storage.OneDrive.OneDriveFolder.GetParentAsync(System.Threading.CancellationToken)">
<inheritdoc />
</member>
</members>
</doc>
File diff suppressed because it is too large Load Diff