Added SimpleWavSplitter.Shared project
This commit is contained in:
Родитель
4f5b713cb0
Коммит
63b511dd1e
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26403.7
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleWavSplitter.Wpf", "src\SimpleWavSplitter.Wpf\SimpleWavSplitter.Wpf.csproj", "{746BB582-59A3-409A-A9C9-53CCFC287D3F}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
|
@ -34,7 +34,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{2C2B9DE5
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleWavSplitter.Avalonia", "src\SimpleWavSplitter.Avalonia\SimpleWavSplitter.Avalonia.csproj", "{FFECA3C3-2785-4AAC-B9DE-5FA47415444F}"
|
||||
EndProject
|
||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SimpleWavSplitter.Shared", "src\SimpleWavSplitter.Shared\SimpleWavSplitter.Shared.shproj", "{AE235C3B-7C24-42B2-8AB0-8C415BA591BE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
src\SimpleWavSplitter.Shared\SimpleWavSplitter.Shared.projitems*{746bb582-59a3-409a-a9c9-53ccfc287d3f}*SharedItemsImports = 4
|
||||
src\SimpleWavSplitter.Shared\SimpleWavSplitter.Shared.projitems*{ae235c3b-7c24-42b2-8ab0-8c415ba591be}*SharedItemsImports = 13
|
||||
src\SimpleWavSplitter.Shared\SimpleWavSplitter.Shared.projitems*{ffeca3c3-2785-4aac-b9de-5fa47415444f}*SharedItemsImports = 4
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|Mono = Debug|Mono
|
||||
|
@ -81,5 +88,6 @@ Global
|
|||
{76465033-784D-46A6-929B-B4B35E7D422E} = {4E9F76C0-2C43-4BEC-91D3-9F76936EB77F}
|
||||
{0DB24D15-3920-44C4-83FA-89D0F7565E42} = {4E9F76C0-2C43-4BEC-91D3-9F76936EB77F}
|
||||
{FFECA3C3-2785-4AAC-B9DE-5FA47415444F} = {4E9F76C0-2C43-4BEC-91D3-9F76936EB77F}
|
||||
{AE235C3B-7C24-42B2-8AB0-8C415BA591BE} = {4E9F76C0-2C43-4BEC-91D3-9F76936EB77F}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -1,17 +1,10 @@
|
|||
// Copyright (c) Wiesław Šoltés. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Threading;
|
||||
using WavFile;
|
||||
|
||||
namespace SimpleWavSplitter.Avalonia
|
||||
{
|
||||
|
@ -20,7 +13,7 @@ namespace SimpleWavSplitter.Avalonia
|
|||
/// </summary>
|
||||
public class MainWindow : Window
|
||||
{
|
||||
private CancellationTokenSource _tokenSource;
|
||||
private SimpleWavFileSplitter _wavFileSplitter;
|
||||
private Button btnGetWavHeader;
|
||||
private ProgressBar progress;
|
||||
private Button btnCancel;
|
||||
|
@ -37,6 +30,8 @@ namespace SimpleWavSplitter.Avalonia
|
|||
this.InitializeComponent();
|
||||
App.AttachDevTools(this);
|
||||
|
||||
_wavFileSplitter = new SimpleWavFileSplitter();
|
||||
|
||||
btnGetWavHeader = this.FindControl<Button>("btnGetWavHeader");
|
||||
progress = this.FindControl<ProgressBar>("progress");
|
||||
btnCancel = this.FindControl<Button>("btnCancel");
|
||||
|
@ -45,13 +40,14 @@ namespace SimpleWavSplitter.Avalonia
|
|||
btnBrowseOutputPath = this.FindControl<Button>("btnBrowseOutputPath");
|
||||
textOutput = this.FindControl<TextBox>("textOutput");
|
||||
|
||||
var v = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
Title = string.Format("SimpleWavSplitter v{0}.{1}.{2}", v.Major, v.Minor, v.Build);
|
||||
var version = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
Title = string.Format("SimpleWavSplitter v{0}.{1}.{2}", version.Major, version.Minor, version.Build);
|
||||
|
||||
btnBrowseOutputPath.Click += async (sender, e) => await GetOutputPath();
|
||||
btnGetWavHeader.Click += async (sender, e) => await GetWavHeader();
|
||||
btnSplitWavFiles.Click += async (sender, e) => await SplitWavFiles();
|
||||
btnCancel.Click += async (sender, e) => await CancelSplitWavFiles();
|
||||
btnCancel.Click += async (sender, e) => await _wavFileSplitter.CancelSplitWavFiles(
|
||||
value => Dispatcher.UIThread.InvokeAsync(() => progress.Value = value));
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
|
@ -86,7 +82,7 @@ namespace SimpleWavSplitter.Avalonia
|
|||
var result = await dlg.ShowAsync();
|
||||
if (result != null)
|
||||
{
|
||||
GetWavHeader(result, (text) => textOutput.Text = text);
|
||||
_wavFileSplitter.GetWavHeader(result, text => textOutput.Text = text);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,120 +96,12 @@ namespace SimpleWavSplitter.Avalonia
|
|||
var result = await dlg.ShowAsync();
|
||||
if (result != null)
|
||||
{
|
||||
await SplitWavFiles(
|
||||
await _wavFileSplitter.SplitWavFiles(
|
||||
result,
|
||||
(text) => Dispatcher.UIThread.InvokeAsync(() => textOutput.Text = text));
|
||||
textOutputPath.Text,
|
||||
value => Dispatcher.UIThread.InvokeAsync(() => progress.Value = value),
|
||||
text => Dispatcher.UIThread.InvokeAsync(() => textOutput.Text = text));
|
||||
}
|
||||
}
|
||||
|
||||
private void GetWavHeader(string[] fileNames, Action<string> setOutput)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
int totalFiles = 0;
|
||||
foreach (string fileName in fileNames)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var fs = File.OpenRead(fileName))
|
||||
{
|
||||
var h = WavFileInfo.ReadFileHeader(fs);
|
||||
if (totalFiles > 0)
|
||||
{
|
||||
sb.Append("\n\n");
|
||||
}
|
||||
sb.Append(
|
||||
string.Format(
|
||||
"FileName:\t\t{0}\nFileSize:\t\t{1}\n{2}",
|
||||
Path.GetFileName(fileName), fs.Length.ToString(), h.ToString()));
|
||||
totalFiles++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string text = string.Format("Error: {0}\n", ex.Message);
|
||||
sb.Append(text);
|
||||
setOutput(sb.ToString());
|
||||
}
|
||||
}
|
||||
setOutput(sb.ToString());
|
||||
}
|
||||
|
||||
private async Task SplitWavFiles(string[] fileNames, Action<string> setOutput)
|
||||
{
|
||||
progress.Value = 0;
|
||||
_tokenSource = new CancellationTokenSource();
|
||||
CancellationToken ct = _tokenSource.Token;
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.Append(string.Format("Files to split: {0}\n", fileNames.Count()));
|
||||
textOutput.Text = sb.ToString();
|
||||
|
||||
string userOutputPath = textOutputPath.Text;
|
||||
|
||||
if (userOutputPath.EndsWith("\\") == false && userOutputPath.Length > 0)
|
||||
{
|
||||
userOutputPath += "\\";
|
||||
}
|
||||
|
||||
long totalBytesProcessed = await Task<long>.Factory.StartNew(() =>
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
long countBytesTotal = 0;
|
||||
|
||||
var splitter = new WavFileSplitter(
|
||||
value => Dispatcher.UIThread.InvokeAsync(() => progress.Value = value));
|
||||
|
||||
foreach (string fileName in fileNames)
|
||||
{
|
||||
try
|
||||
{
|
||||
string outputPath = userOutputPath.Length > 0 ?
|
||||
userOutputPath :
|
||||
fileName.Remove(fileName.Length - Path.GetFileName(fileName).Length);
|
||||
|
||||
sb.Append(
|
||||
string.Format(
|
||||
"Split file: {0}\n",
|
||||
Path.GetFileName(fileName)));
|
||||
|
||||
setOutput(sb.ToString());
|
||||
|
||||
countBytesTotal += splitter.SplitWavFile(fileName, outputPath, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sb.Append(string.Format("Error: {0}\n", ex.Message));
|
||||
|
||||
setOutput(sb.ToString());
|
||||
|
||||
return countBytesTotal;
|
||||
}
|
||||
}
|
||||
return countBytesTotal;
|
||||
}, ct);
|
||||
|
||||
sw.Stop();
|
||||
if (_tokenSource.IsCancellationRequested == false)
|
||||
{
|
||||
string text = string.Format(
|
||||
"Done.\nData bytes processed: {0} ({1} MB)\nElapsed time: {2}\n",
|
||||
totalBytesProcessed,
|
||||
Math.Round((double)totalBytesProcessed / (1024 * 1024), 1),
|
||||
sw.Elapsed);
|
||||
sb.Append(text);
|
||||
setOutput(sb.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CancelSplitWavFiles()
|
||||
{
|
||||
if (_tokenSource != null)
|
||||
{
|
||||
await Task.Factory.StartNew(() => _tokenSource.Cancel());
|
||||
}
|
||||
progress.Value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -193,6 +193,7 @@
|
|||
<Name>WavFile</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="..\SimpleWavSplitter.Shared\SimpleWavSplitter.Shared.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
// Copyright (c) Wiesław Šoltés. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using WavFile;
|
||||
|
||||
namespace SimpleWavSplitter
|
||||
{
|
||||
public class SimpleWavFileSplitter
|
||||
{
|
||||
private CancellationTokenSource _tokenSource;
|
||||
|
||||
public void GetWavHeader(string[] fileNames, Action<string> setOutput)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
int totalFiles = 0;
|
||||
foreach (string fileName in fileNames)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var fs = File.OpenRead(fileName))
|
||||
{
|
||||
var h = WavFileInfo.ReadFileHeader(fs);
|
||||
if (totalFiles > 0)
|
||||
{
|
||||
sb.Append("\n\n");
|
||||
}
|
||||
sb.Append(
|
||||
string.Format(
|
||||
"FileName:\t\t{0}\nFileSize:\t\t{1}\n{2}",
|
||||
Path.GetFileName(fileName), fs.Length.ToString(), h.ToString()));
|
||||
totalFiles++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string text = string.Format("Error: {0}\n", ex.Message);
|
||||
sb.Append(text);
|
||||
setOutput(sb.ToString());
|
||||
}
|
||||
}
|
||||
setOutput(sb.ToString());
|
||||
}
|
||||
|
||||
public async Task SplitWavFiles(string[] files, string path, Action<double> setProgress, Action<string> setOutput)
|
||||
{
|
||||
setProgress(0);
|
||||
_tokenSource = new CancellationTokenSource();
|
||||
CancellationToken ct = _tokenSource.Token;
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.Append(string.Format("Files to split: {0}\n", files.Count()));
|
||||
setOutput(sb.ToString());
|
||||
|
||||
if (path.EndsWith("\\") == false && path.Length > 0)
|
||||
{
|
||||
path += "\\";
|
||||
}
|
||||
|
||||
long totalBytesProcessed = await Task<long>.Factory.StartNew(() =>
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
long countBytesTotal = 0;
|
||||
|
||||
var splitter = new WavFileSplitter(setProgress);
|
||||
|
||||
foreach (string fileName in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
string outputPath = path.Length > 0 ?
|
||||
path :
|
||||
fileName.Remove(fileName.Length - Path.GetFileName(fileName).Length);
|
||||
|
||||
sb.Append(
|
||||
string.Format(
|
||||
"Split file: {0}\n",
|
||||
Path.GetFileName(fileName)));
|
||||
|
||||
setOutput(sb.ToString());
|
||||
|
||||
countBytesTotal += splitter.SplitWavFile(fileName, outputPath, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sb.Append(string.Format("Error: {0}\n", ex.Message));
|
||||
|
||||
setOutput(sb.ToString());
|
||||
|
||||
return countBytesTotal;
|
||||
}
|
||||
}
|
||||
return countBytesTotal;
|
||||
}, ct);
|
||||
|
||||
sw.Stop();
|
||||
if (_tokenSource.IsCancellationRequested == false)
|
||||
{
|
||||
string text = string.Format(
|
||||
"Done.\nData bytes processed: {0} ({1} MB)\nElapsed time: {2}\n",
|
||||
totalBytesProcessed,
|
||||
Math.Round((double)totalBytesProcessed / (1024 * 1024), 1),
|
||||
sw.Elapsed);
|
||||
sb.Append(text);
|
||||
setOutput(sb.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CancelSplitWavFiles(Action<double> setProgress)
|
||||
{
|
||||
if (_tokenSource != null)
|
||||
{
|
||||
await Task.Factory.StartNew(() => _tokenSource.Cancel());
|
||||
}
|
||||
setProgress(0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
|
||||
<HasSharedItems>true</HasSharedItems>
|
||||
<SharedGUID>ae235c3b-7c24-42b2-8ab0-8c415ba591be</SharedGUID>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<Import_RootNamespace>SimpleWavSplitter.Shared</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)SimpleWavFileSplitter.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>ae235c3b-7c24-42b2-8ab0-8c415ba591be</ProjectGuid>
|
||||
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
|
||||
<PropertyGroup />
|
||||
<Import Project="SimpleWavSplitter.Shared.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
||||
</Project>
|
|
@ -1,17 +1,10 @@
|
|||
// Copyright (c) Wiesław Šoltés. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
using Microsoft.Win32;
|
||||
using WavFile;
|
||||
|
||||
namespace SimpleWavSplitter.Wpf
|
||||
{
|
||||
|
@ -20,7 +13,7 @@ namespace SimpleWavSplitter.Wpf
|
|||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private CancellationTokenSource _tokenSource;
|
||||
private SimpleWavFileSplitter _wavFileSplitter;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the new instance of <see cref="MainWindow"/> class.
|
||||
|
@ -29,13 +22,16 @@ namespace SimpleWavSplitter.Wpf
|
|||
{
|
||||
InitializeComponent();
|
||||
|
||||
var v = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
Title = string.Format("SimpleWavSplitter v{0}.{1}.{2}", v.Major, v.Minor, v.Build);
|
||||
_wavFileSplitter = new SimpleWavFileSplitter();
|
||||
|
||||
var version = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
Title = string.Format("SimpleWavSplitter v{0}.{1}.{2}", version.Major, version.Minor, version.Build);
|
||||
|
||||
btnBrowseOutputPath.Click += (sender, e) => GetOutputPath();
|
||||
btnGetWavHeader.Click += (sender, e) => GetWavHeader();
|
||||
btnSplitWavFiles.Click += async (sender, e) => await SplitWavFiles();
|
||||
btnCancel.Click += async (sender, e) => await CancelSplitWavFiles();
|
||||
btnCancel.Click += async (sender, e) => await _wavFileSplitter.CancelSplitWavFiles(
|
||||
value => Dispatcher.Invoke(() => progress.Value = value));
|
||||
}
|
||||
|
||||
private void GetOutputPath()
|
||||
|
@ -55,140 +51,36 @@ namespace SimpleWavSplitter.Wpf
|
|||
|
||||
private void GetWavHeader()
|
||||
{
|
||||
var dlg = new OpenFileDialog();
|
||||
dlg.Filter = "WAV Files (*.wav)|*.wav|All Files (*.*)|*.*";
|
||||
dlg.FilterIndex = 0;
|
||||
dlg.Multiselect = true;
|
||||
var dlg = new OpenFileDialog()
|
||||
{
|
||||
Filter = "WAV Files (*.wav)|*.wav|All Files (*.*)|*.*",
|
||||
FilterIndex = 0,
|
||||
Multiselect = true
|
||||
};
|
||||
|
||||
if (dlg.ShowDialog() == true)
|
||||
{
|
||||
GetWavHeader(dlg.FileNames, (text) => textOutput.Text = text);
|
||||
_wavFileSplitter.GetWavHeader(dlg.FileNames, text => textOutput.Text = text);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SplitWavFiles()
|
||||
{
|
||||
var dlg = new OpenFileDialog();
|
||||
dlg.Filter = "WAV Files (*.wav)|*.wav|All Files (*.*)|*.*";
|
||||
dlg.FilterIndex = 0;
|
||||
dlg.Multiselect = true;
|
||||
var dlg = new OpenFileDialog()
|
||||
{
|
||||
Filter = "WAV Files (*.wav)|*.wav|All Files (*.*)|*.*",
|
||||
FilterIndex = 0,
|
||||
Multiselect = true
|
||||
};
|
||||
|
||||
if (dlg.ShowDialog() == true)
|
||||
{
|
||||
await SplitWavFiles(
|
||||
await _wavFileSplitter.SplitWavFiles(
|
||||
dlg.FileNames,
|
||||
(text) => Dispatcher.Invoke(() => textOutput.Text = text));
|
||||
textOutputPath.Text,
|
||||
value => Dispatcher.Invoke(() => progress.Value = value),
|
||||
text => Dispatcher.Invoke(() => textOutput.Text = text));
|
||||
}
|
||||
}
|
||||
|
||||
private void GetWavHeader(string[] fileNames, Action<string> setOutput)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
int totalFiles = 0;
|
||||
foreach (string fileName in fileNames)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var fs = File.OpenRead(fileName))
|
||||
{
|
||||
var h = WavFileInfo.ReadFileHeader(fs);
|
||||
if (totalFiles > 0)
|
||||
{
|
||||
sb.Append("\n\n");
|
||||
}
|
||||
sb.Append(
|
||||
string.Format(
|
||||
"FileName:\t\t{0}\nFileSize:\t\t{1}\n{2}",
|
||||
Path.GetFileName(fileName), fs.Length.ToString(), h.ToString()));
|
||||
totalFiles++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string text = string.Format("Error: {0}\n", ex.Message);
|
||||
sb.Append(text);
|
||||
setOutput(sb.ToString());
|
||||
}
|
||||
}
|
||||
setOutput(sb.ToString());
|
||||
}
|
||||
|
||||
private async Task SplitWavFiles(string[] fileNames, Action<string> setOutput)
|
||||
{
|
||||
progress.Value = 0;
|
||||
_tokenSource = new CancellationTokenSource();
|
||||
CancellationToken ct = _tokenSource.Token;
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.Append(string.Format("Files to split: {0}\n", fileNames.Count()));
|
||||
textOutput.Text = sb.ToString();
|
||||
|
||||
string userOutputPath = textOutputPath.Text;
|
||||
|
||||
if (userOutputPath.EndsWith("\\") == false && userOutputPath.Length > 0)
|
||||
{
|
||||
userOutputPath += "\\";
|
||||
}
|
||||
|
||||
long totalBytesProcessed = await Task<long>.Factory.StartNew(() =>
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
long countBytesTotal = 0;
|
||||
|
||||
var splitter = new WavFileSplitter(
|
||||
value => Dispatcher.Invoke(() => progress.Value = value));
|
||||
|
||||
foreach (string fileName in fileNames)
|
||||
{
|
||||
try
|
||||
{
|
||||
string outputPath = userOutputPath.Length > 0 ?
|
||||
userOutputPath :
|
||||
fileName.Remove(fileName.Length - Path.GetFileName(fileName).Length);
|
||||
|
||||
sb.Append(
|
||||
string.Format(
|
||||
"Split file: {0}\n",
|
||||
Path.GetFileName(fileName)));
|
||||
|
||||
setOutput(sb.ToString());
|
||||
|
||||
countBytesTotal += splitter.SplitWavFile(fileName, outputPath, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
sb.Append(string.Format("Error: {0}\n", ex.Message));
|
||||
|
||||
setOutput(sb.ToString());
|
||||
|
||||
return countBytesTotal;
|
||||
}
|
||||
}
|
||||
return countBytesTotal;
|
||||
}, ct);
|
||||
|
||||
sw.Stop();
|
||||
if (_tokenSource.IsCancellationRequested == false)
|
||||
{
|
||||
string text = string.Format(
|
||||
"Done.\nData bytes processed: {0} ({1} MB)\nElapsed time: {2}\n",
|
||||
totalBytesProcessed,
|
||||
Math.Round((double)totalBytesProcessed / (1024 * 1024), 1),
|
||||
sw.Elapsed);
|
||||
sb.Append(text);
|
||||
setOutput(sb.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CancelSplitWavFiles()
|
||||
{
|
||||
if (_tokenSource != null)
|
||||
{
|
||||
await Task.Factory.StartNew(() => _tokenSource.Cancel());
|
||||
}
|
||||
progress.Value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,6 +140,7 @@
|
|||
<Name>WavFile</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="..\SimpleWavSplitter.Shared\SimpleWavSplitter.Shared.projitems" Label="Shared" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
Загрузка…
Ссылка в новой задаче