Skip to content

Commit

Permalink
unified import files
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoCoderMatrix86 committed Aug 29, 2024
1 parent fe13f85 commit 31c440d
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 109 deletions.
23 changes: 2 additions & 21 deletions AudioCuesheetEditor/Extensions/SessionStateContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ public Cuesheet? ImportCuesheet
}
}

public TextImportfile? TextImportFile { get; set; }

public CuesheetImportfile? CuesheetImportFile{ get; set; }

public Audiofile? ImportAudiofile
{
get => importAudiofile;
Expand All @@ -91,26 +87,11 @@ public ViewMode CurrentViewMode
}
}

public IImportfile? Importfile
{
get
{
if (TextImportFile != null)
{
return TextImportFile;
}
if (CuesheetImportFile != null)
{
return CuesheetImportFile;
}
return null;
}
}
public IImportfile? Importfile{ get; set; }

public void ResetImport()
{
TextImportFile = null;
CuesheetImportFile = null;
Importfile = null;
ImportAudiofile = null;
}

Expand Down
3 changes: 0 additions & 3 deletions AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ public class CuesheetSectionAddRemoveEventArgs(CuesheetSection section) : EventA

public class Cuesheet(TraceChangeManager? traceChangeManager = null) : Validateable<Cuesheet>, ITraceable, ICuesheet
{
public const String MimeType = "text/*";
public const String FileExtension = ".cue";

private readonly object syncLock = new();

private List<Track> tracks = [];
Expand Down
2 changes: 1 addition & 1 deletion AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public IReadOnlyCollection<Exportfile> GenerateExportfiles()
{
case ExportType.Cuesheet:
content = WriteCuesheet(audioFileName, section);
filename = String.Format("{0}({1}){2}", Path.GetFileNameWithoutExtension(ApplicationOptions?.CuesheetFilename), counter, Cuesheet.FileExtension);
filename = String.Format("{0}({1}){2}", Path.GetFileNameWithoutExtension(ApplicationOptions?.CuesheetFilename), counter, FileExtensions.Cuesheet);
break;
case ExportType.Exportprofile:
if (Exportprofile != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//This file is part of AudioCuesheetEditor.
//This file is part of AudioCuesheetEditor.

//AudioCuesheetEditor is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
Expand All @@ -13,22 +13,12 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using AudioCuesheetEditor.Model.AudioCuesheet.Import;

namespace AudioCuesheetEditor.Model.IO.Import
namespace AudioCuesheetEditor.Model.IO
{
public class TextImportfile : IImportfile
public class FileExtensions
{
public const String MimeType = "text/plain";
public const String FileExtension = ".txt";

/// <inheritdoc />
public IEnumerable<String?>? FileContent { get; set; }
/// <inheritdoc />
public IEnumerable<String?>? FileContentRecognized { get; set; }
/// <inheritdoc />
public Exception? AnalyseException { get;set; }
/// <inheritdoc />
public ImportCuesheet? AnalysedCuesheet { get; set; }
public const string Text = ".txt";
public const string Projectfile = ".ace";
public const string Cuesheet = ".cue";
}
}
24 changes: 24 additions & 0 deletions AudioCuesheetEditor/Model/IO/FileMimeTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//This file is part of AudioCuesheetEditor.

//AudioCuesheetEditor is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//AudioCuesheetEditor is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
namespace AudioCuesheetEditor.Model.IO
{
public static class FileMimeTypes
{
public const string Text = "text/plain";
public const string Projectfile = "text/*";
public const string Cuesheet = "text/*";
}
}
2 changes: 2 additions & 0 deletions AudioCuesheetEditor/Model/IO/Import/IImportfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Services.IO;

namespace AudioCuesheetEditor.Model.IO.Import
{
Expand All @@ -35,5 +36,6 @@ public interface IImportfile
/// The cuesheet which was created during analysing the <see cref="FileContent"/>
/// </summary>
ImportCuesheet? AnalysedCuesheet { get; set; }
ImportFileType FileType { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//This file is part of AudioCuesheetEditor.
//This file is part of AudioCuesheetEditor.

//AudioCuesheetEditor is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
Expand All @@ -14,10 +14,11 @@
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Services.IO;

namespace AudioCuesheetEditor.Model.IO.Import
{
public class CuesheetImportfile : IImportfile
public class Importfile : IImportfile
{
/// <inheritdoc />
public IEnumerable<String?>? FileContent { get; set; }
Expand All @@ -27,5 +28,6 @@ public class CuesheetImportfile : IImportfile
public Exception? AnalyseException { get; set; }
/// <inheritdoc />
public ImportCuesheet? AnalysedCuesheet { get; set; }
public ImportFileType FileType { get; set; }
}
}
3 changes: 0 additions & 3 deletions AudioCuesheetEditor/Model/IO/Projectfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ namespace AudioCuesheetEditor.Model.IO
{
public class Projectfile(Cuesheet cuesheet)
{
public const String MimeType = "text/*";
public const String FileExtension = ".ace";

public static readonly String DefaultFilename = "Project.ace";

public static readonly JsonSerializerOptions Options = new()
Expand Down
8 changes: 4 additions & 4 deletions AudioCuesheetEditor/Model/Options/ApplicationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ protected override ValidationResult Validate(string property)
else
{
var extension = Path.GetExtension(CuesheetFilename);
if (extension.Equals(Cuesheet.FileExtension, StringComparison.OrdinalIgnoreCase) == false)
if (extension.Equals(FileExtensions.Cuesheet, StringComparison.OrdinalIgnoreCase) == false)
{
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} must end with '{1}'!", nameof(CuesheetFilename), Cuesheet.FileExtension));
validationMessages.Add(new ValidationMessage("{0} must end with '{1}'!", nameof(CuesheetFilename), FileExtensions.Cuesheet));
}
var filenameWithoutExtension = Path.GetFileNameWithoutExtension(CuesheetFilename);
if (string.IsNullOrEmpty(filenameWithoutExtension))
Expand All @@ -133,10 +133,10 @@ protected override ValidationResult Validate(string property)
else
{
var extension = Path.GetExtension(ProjectFilename);
if (extension.Equals(Projectfile.FileExtension, StringComparison.OrdinalIgnoreCase) == false)
if (extension.Equals(FileExtensions.Projectfile, StringComparison.OrdinalIgnoreCase) == false)
{
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} must end with '{1}'!", nameof(ProjectFilename), Projectfile.FileExtension));
validationMessages.Add(new ValidationMessage("{0} must end with '{1}'!", nameof(ProjectFilename), FileExtensions.Projectfile));
}
var filename = Path.GetFileNameWithoutExtension(ProjectFilename);
if (String.IsNullOrEmpty(filename))
Expand Down
8 changes: 4 additions & 4 deletions AudioCuesheetEditor/Model/Utility/IOUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public static Boolean CheckFileMimeType(IFileEntry file, String mimeType, String
{
if (String.IsNullOrEmpty(file.Type) == false)
{
fileMimeTypeMatches = file.Type.ToLower() == mimeType.ToLower();
fileMimeTypeMatches = file.Type.Equals(mimeType, StringComparison.CurrentCultureIgnoreCase);
}
else
{
//Try to find by file extension
var extension = Path.GetExtension(file.Name).ToLower();
fileMimeTypeMatches = extension == fileExtension.ToLower();
var extension = Path.GetExtension(file.Name);
fileMimeTypeMatches = extension.Equals(fileExtension, StringComparison.CurrentCultureIgnoreCase);
}
}
return fileMimeTypeMatches;
Expand All @@ -47,7 +47,7 @@ public static Boolean CheckFileMimeTypeForAudioCodec(IFileEntry file)
public static AudioCodec? GetAudioCodec(IFileEntry fileEntry)
{
AudioCodec? foundAudioCodec = null;
var extension = Path.GetExtension(fileEntry.Name).ToLower();
var extension = Path.GetExtension(fileEntry.Name);
// First search with mime type and file extension
var audioCodecsFound = Audiofile.AudioCodecs.Where(x => x.MimeType.Equals(fileEntry.Type, StringComparison.OrdinalIgnoreCase) && x.FileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase));
if (audioCodecsFound.Count() <= 1)
Expand Down
32 changes: 16 additions & 16 deletions AudioCuesheetEditor/Pages/ViewModeImport.razor
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ along with Foobar. If not, see
<Field Horizontal="true">
<FieldLabel ColumnSize="ColumnSize.Is2.OnFullHD.Is3.OnDesktop.Is4.OnTablet.Is5.OnMobile">@_localizer["Textfile"]</FieldLabel>
<FieldBody ColumnSize="ColumnSize.Is10.OnFullHD.Is9.OnDesktop.Is8.OnTablet.Is12.OnMobile">
<FileEdit Filter="@TextImportfile.MimeType" Changed="OnTextImportFileChanged" AutoReset="false"></FileEdit>
<FileEdit Filter="@FileMimeTypes.Text" Changed="OnTextImportFileChanged" AutoReset="false"></FileEdit>
</FieldBody>
</Field>
</Tooltip>
Expand All @@ -72,7 +72,7 @@ along with Foobar. If not, see
<Field Horizontal="true">
<FieldLabel ColumnSize="ColumnSize.Is2.OnFullHD.Is3.OnDesktop.Is4.OnTablet.Is5.OnMobile">@_localizer["Cuesheet"]</FieldLabel>
<FieldBody ColumnSize="ColumnSize.Is10.OnFullHD.Is9.OnDesktop.Is8.OnTablet.Is12.OnMobile">
<FileEdit Filter="@Cuesheet.FileExtension" Changed="OnCuesheetfileChanged" AutoReset="false"></FileEdit>
<FileEdit Filter="@FileExtensions.Cuesheet" Changed="OnCuesheetfileChanged" AutoReset="false"></FileEdit>
</FieldBody>
</Field>
</Tooltip>
Expand All @@ -88,7 +88,7 @@ along with Foobar. If not, see
<Field Horizontal="true">
<FieldLabel ColumnSize="ColumnSize.Is2.OnFullHD.Is3.OnDesktop.Is4.OnTablet.Is5.OnMobile">@_localizer["Project filename"]</FieldLabel>
<FieldBody ColumnSize="ColumnSize.Is10.OnFullHD.Is9.OnDesktop.Is8.OnTablet.Is12.OnMobile">
<FileEdit Filter="@Projectfile.FileExtension" Changed="OnProjectfileChanged" AutoReset="false"></FileEdit>
<FileEdit Filter="@FileExtensions.Projectfile" Changed="OnProjectfileChanged" AutoReset="false"></FileEdit>
</FieldBody>
</Field>
</Tooltip>
Expand Down Expand Up @@ -147,7 +147,7 @@ along with Foobar. If not, see
</Field>
</CollapseBody>
</Collapse>
@if (_sessionStateContainer.TextImportFile?.AnalyseException != null)
@if (_sessionStateContainer.Importfile?.AnalyseException != null)
{
<Alert Color="Color.Danger" Visible="true">
<AlertDescription>
Expand All @@ -156,7 +156,7 @@ along with Foobar. If not, see
<path d="M7.002 11a1 1 0 1 1 2 0 1 1 0 0 1-2 0zM7.1 4.995a.905.905 0 1 1 1.8 0l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 4.995z" />
</svg>
</AlertDescription>
<AlertMessage>@_localizer["Error during textimport"] : @_sessionStateContainer.TextImportFile.AnalyseException.Message</AlertMessage>
<AlertMessage>@_localizer["Error during textimport"] : @_sessionStateContainer.Importfile.AnalyseException.Message</AlertMessage>
</Alert>
}
}
Expand Down Expand Up @@ -199,7 +199,7 @@ along with Foobar. If not, see

@code {
String selectedStep = "selectFiles";
String dragNDropUploadFilter = String.Join(',', TextImportfile.MimeType, Cuesheet.FileExtension, Projectfile.FileExtension);
String dragNDropUploadFilter = String.Join(',', FileMimeTypes.Text, FileExtensions.Cuesheet, FileExtensions.Projectfile);
Boolean cuesheetDataVisible = true;
Boolean cuesheetTracksVisible = true;
Boolean cuesheetSplitPointsVisible = true;
Expand Down Expand Up @@ -247,7 +247,7 @@ along with Foobar. If not, see
selectedStep = name;
break;
case "validateData":
if ((_sessionStateContainer.ImportCuesheet != null) || (_sessionStateContainer.TextImportFile != null))
if ((_sessionStateContainer.ImportCuesheet != null) || (_sessionStateContainer.Importfile != null))
{
selectFilesCompleted = true;
selectedStep = name;
Expand All @@ -271,7 +271,7 @@ along with Foobar. If not, see
{
get
{
if ((userChangedSelectedStep == false) && ((_sessionStateContainer.ImportCuesheet != null) || (_sessionStateContainer.TextImportFile != null)))
if ((userChangedSelectedStep == false) && ((_sessionStateContainer.ImportCuesheet != null) || (_sessionStateContainer.Importfile != null)))
{
selectFilesCompleted = true;
selectedStep = "validateData";
Expand All @@ -286,7 +286,7 @@ along with Foobar. If not, see
if (e.Files.FirstOrDefault() != null)
{
var file = e.Files.First();
if (IOUtility.CheckFileMimeType(file, TextImportfile.MimeType, TextImportfile.FileExtension) == false)
if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Text, FileExtensions.Text) == false)
{
invalidTextImportFileNames.Add(file.Name);
}
Expand All @@ -304,7 +304,7 @@ along with Foobar. If not, see
if (e.Files.FirstOrDefault() != null)
{
var file = e.Files.First();
if (IOUtility.CheckFileMimeType(file, Cuesheet.MimeType, Cuesheet.FileExtension) == false)
if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Cuesheet, FileExtensions.Cuesheet) == false)
{
invalidCuesheetfileNames.Add(file.Name);
}
Expand All @@ -322,7 +322,7 @@ along with Foobar. If not, see
if (e.Files.FirstOrDefault() != null)
{
var file = e.Files.First();
if (IOUtility.CheckFileMimeType(file, Projectfile.MimeType, Projectfile.FileExtension) == false)
if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Projectfile, FileExtensions.Projectfile) == false)
{
invalidProjectfileNames.Add(file.Name);
}
Expand All @@ -339,9 +339,9 @@ along with Foobar. If not, see
invalidDropFileNames.Clear();
foreach (var file in e.Files)
{
if ((IOUtility.CheckFileMimeType(file, Projectfile.MimeType, Projectfile.FileExtension) == false)
&& (IOUtility.CheckFileMimeType(file, Cuesheet.MimeType, Cuesheet.FileExtension) == false)
&& (IOUtility.CheckFileMimeType(file, TextImportfile.MimeType, TextImportfile.FileExtension) == false)
if ((IOUtility.CheckFileMimeType(file, FileMimeTypes.Projectfile, FileExtensions.Projectfile) == false)
&& (IOUtility.CheckFileMimeType(file, FileMimeTypes.Cuesheet, FileExtensions.Cuesheet) == false)
&& (IOUtility.CheckFileMimeType(file, FileMimeTypes.Text, FileExtensions.Text) == false)
&& (IOUtility.CheckFileMimeTypeForAudioCodec(file) == false))
{
invalidDropFileNames.Add(file.Name);
Expand Down Expand Up @@ -469,9 +469,9 @@ along with Foobar. If not, see

async Task EditImportOptions_OptionsChanged(ImportOptions importOptions)
{
if (_sessionStateContainer.TextImportFile?.FileContent != null)
if ((_sessionStateContainer.Importfile?.FileType == ImportFileType.Textfile) && (_sessionStateContainer.Importfile?.FileContent != null))
{
await _importManager.ImportTextAsync(_sessionStateContainer.TextImportFile.FileContent);
await _importManager.ImportTextAsync(_sessionStateContainer.Importfile.FileContent);
}
}
}
Loading

0 comments on commit 31c440d

Please sign in to comment.