Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add oudep dependency download center #931

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions OpenUtau.Core/Util/WebFileDownloader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;

namespace OpenUtau.Core.Util {
public static class WebFileDownloader {
/// <summary>
/// downloads file from [address] in web, and saves as [filename] in "Cache" folder.
/// returns true if file download completed successfully, otherwise false.
/// it's async process, so must call .Wait() when use.
/// </summary>
public static async Task DownLoadFileAsyncInCache(string address, string filename)
{
WebClient client = new WebClient();
Uri uri = new Uri(address);
bool isSuccessed = false;
bool isCompleted = false;

client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback4);

await client.DownloadFileTaskAsync(uri, Path.Combine(PathManager.Inst.CachePath, filename)).ConfigureAwait(false);

}


private static void DownloadProgressCallback4(object sender, DownloadProgressChangedEventArgs e)
{
// Displays the operation identifier, and the transfer progress.
DocManager.Inst.ExecuteCmd(new ProgressBarNotification(e.ProgressPercentage, $"Please Wait... OU is Downloading Dependency from web: {Math.Round(e.BytesReceived / Math.Pow(1024, 2), 2)}MB / {Math.Round(e.TotalBytesToReceive / Math.Pow(1024, 2), 2)}MB."));

}
}

}
10 changes: 10 additions & 0 deletions OpenUtau.Plugin.Builtin/Data/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions OpenUtau.Plugin.Builtin/Data/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,7 @@
<data name="german_template" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>german.template.yaml;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="download_center_template" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>download-center.template.yaml;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
17 changes: 17 additions & 0 deletions OpenUtau.Plugin.Builtin/Data/download-center.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
%YAML 1.2
---
categories:
#types of dependencies
- Classic
- WORLDLINE-R
- ENUNU
- Diffsinger
- Vogen

dependencies:
- {
name: nsf_hifiGAN,
category: Diffsinger,
link: https://github.com/xunmengshe/OpenUtau/releases/download/0.0.0.0/nsf_hifigan.oudep,
meta: {size(mb): 50, version: 1.0.0, info: -}
}
43 changes: 43 additions & 0 deletions OpenUtau.Plugin.Builtin/DownloadCenter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.IO;
using System.Text;
using OpenUtau.Core;

namespace OpenUtau.Plugin.Builtin {
public class DownloadCenterManager {
public Categories categories;
public DownloadCenterManager() {
var yamlFile = Path.Combine(PathManager.Inst.PluginsPath, "download center.yaml");
if (File.Exists(yamlFile)) {
using (var stream = File.OpenRead(yamlFile)) {
categories = Load(stream);
}
}
else {
Directory.CreateDirectory(PathManager.Inst.PluginsPath);
File.WriteAllBytes(yamlFile, Data.Resources.download_center_template);
using (var stream = File.OpenRead(yamlFile)) {
categories = Load(stream);
}
}
}

private static Categories Load(Stream stream) {
using (var reader = new StreamReader(stream, Encoding.UTF8)) {
// TODO FIx bug
var categoriesConfig = Yaml.DefaultDeserializer.Deserialize<Categories>(reader);
return categoriesConfig;
}
}
}

public class Categories {
public string[] categories;
public string[] dependencies;

public Categories(string[] categories, string[] dependencies) {
this.categories = categories;
this.dependencies = dependencies;
}
}
}
8 changes: 7 additions & 1 deletion OpenUtau/Strings/Strings.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@
<system:String x:Key="menu.tools.singer.install">Install Singer...</system:String>
<system:String x:Key="menu.tools.singer.installadv">Install Singer (Advanced)...</system:String>
<system:String x:Key="menu.tools.singers">Singers...</system:String>

<system:String x:Key="menu.tools.dlcenter">Download Center</system:String>

<system:String x:Key="notedefaults.lyric">Lyric</system:String>
<system:String x:Key="notedefaults.lyric.defaultlyric">Default Lyric</system:String>
<system:String x:Key="notedefaults.portamento">Portamento</system:String>
Expand Down Expand Up @@ -450,6 +451,11 @@ General
<system:String x:Key="tracks.trackcolor">Change track color</system:String>
<system:String x:Key="tracks.tracksettings">Track Settings</system:String>

<system:String x:Key="dlcenter.caption">Dependency Download Center</system:String>
<system:String x:Key="dlcenter.category">Category: </system:String>
<system:String x:Key="dlcenter.download">Download</system:String>
<system:String x:Key="dlcenter.showinfo">Show Information</system:String>

<FontFamily x:Key="ui.fontfamily">Segoe UI,San Francisco,Helvetica Neue</FontFamily>
<FontFamily x:Key="ui.textbox.fontfamily">Microsoft YaHei,Simsun,苹方-简,宋体-简</FontFamily>

Expand Down
31 changes: 31 additions & 0 deletions OpenUtau/ViewModels/DownloadCenterViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.IO;
using System.Text;
using Avalonia.Controls;
using DynamicData.Binding;
using NAudio.Wave;
using NWaves.Signals;
using OpenUtau.Classic;
using OpenUtau.Core;
using OpenUtau.Core.Ustx;
using ReactiveUI;
using OpenUtau.Plugin.Builtin;
using OpenUtau.App.Views;

namespace OpenUtau.App.ViewModels {
public class DownloadCenterViewModel : ViewModelBase {
Categories? appliedCategory;
public Categories? ApplyCategory {
get => appliedCategory;
set => this.RaiseAndSetIfChanged(ref appliedCategory, value);
}

public DownloadCenterViewModel(){
DownloadCenterManager downloadCenterManager = new DownloadCenterManager();
ApplyCategory = downloadCenterManager.categories;
}

}



}
31 changes: 31 additions & 0 deletions OpenUtau/Views/DownloadCenter.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:OpenUtau.App.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="640"
x:Class="OpenUtau.App.Views.DownloadCenter"
Icon="/Assets/open-utau.ico"
Title="{DynamicResource dlcenter.caption}" Width="1050" MinWidth="1050" MinHeight="640"
WindowStartupLocation="CenterScreen"
ExtendClientAreaToDecorationsHint="False">
<Grid ColumnDefinitions="*,10,160" Margin="10">
<TextBlock Grid.Column="0" Text="{DynamicResource dlcenter.category}" VerticalAlignment="Top"/>
<ComboBox Grid.Column="7" ItemsSource="{Binding PortamentoPresets}"
SelectedItem="{Binding ApplyPortamentoPreset}" HorizontalAlignment="Stretch"/>
<!-- <DataGrid Name="SuffixGrid" Grid.Column="0" SelectionMode="Extended" IsReadOnly="True"
CanUserReorderColumns="False" CanUserSortColumns="False" AutoGenerateColumns="False"
ItemsSource="{Binding Rows}" SelectionChanged="OnSelectionChanged">
<DataGrid.Columns>
<DataGridTextColumn Header="{StaticResource singers.subbanks.tone}" Width="*" Binding="{Binding Tone}"/>
<DataGridTextColumn Header="{StaticResource oto.prefix}" Width="*" Binding="{Binding Prefix}"/>
<DataGridTextColumn Header="{StaticResource oto.suffix}" Width="*" Binding="{Binding Suffix}"/>
</DataGrid.Columns>
</DataGrid> -->
<Grid Grid.Column="2">
<Grid RowDefinitions="Auto,*,Auto,*,Auto">

</Grid>
</Grid>
</Grid>
</Window>
19 changes: 19 additions & 0 deletions OpenUtau/Views/DownloadCenter.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.IO;
using System.Linq;
using Avalonia.Controls;
using Avalonia.Interactivity;
using OpenUtau.App.ViewModels;
using OpenUtau.Core;

namespace OpenUtau.App.Views {
public partial class DownloadCenter : Window {
internal readonly DownloadCenterViewModel ViewModel;

public DownloadCenter() {
InitializeComponent();
DataContext = ViewModel = new DownloadCenterViewModel();
}
}

}
1 change: 1 addition & 0 deletions OpenUtau/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<MenuItem Header="{DynamicResource menu.tools.project.expressions}" Click="OnMenuExpressionss"/>
<MenuItem Header="{DynamicResource menu.tools.singers}" Click="OnMenuSingers"/>
<MenuItem Header="{DynamicResource menu.tools.singer.install}" Click="OnMenuInstallSinger"/>
<MenuItem Header="{DynamicResource menu.tools.dlcenter}" Click="OnMenuDownloadCenter"/>
<MenuItem Header="{DynamicResource menu.tools.prefs}" Click="OnMenuPreferences"/>
</MenuItem>
<MenuItem Header="{DynamicResource menu.help}">
Expand Down
12 changes: 12 additions & 0 deletions OpenUtau/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,18 @@ await MessageBox.Show(
return true;
}

void OnMenuDownloadCenter(object sender, RoutedEventArgs args) {
var desktop = Application.Current?.ApplicationLifetime as IClassicDesktopStyleApplicationLifetime;
if (desktop == null) {
return;
}
var window = desktop.Windows.FirstOrDefault(w => w is DownloadCenter);
if (window == null) {
window = new DownloadCenter();
}
window.Show();
}

void OnMenuExpressionss(object sender, RoutedEventArgs args) {
var dialog = new ExpressionsDialog() {
DataContext = new ExpressionsViewModel(),
Expand Down