Skip to content

Commit

Permalink
rename FormatDetector to FormatFactory.
Browse files Browse the repository at this point in the history
  • Loading branch information
clown committed Nov 11, 2022
1 parent c8975c6 commit 60064da
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Applications/Ice/Core/Sources/CompressionQueryValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private void SetDestination(string src)
if (!src.HasValue()) return;

var ext = Io.GetExtension(src).ToLowerInvariant();
var obj = ext == ".exe" ? Format.Sfx : FormatDetector.FromExtension(ext);
var obj = ext == ".exe" ? Format.Sfx : FormatFactory.FromExtension(ext);
if (obj == Format.Unknown) return;

var fmt = obj == Format.GZip || obj == Format.BZip2 || obj == Format.XZ ? Format.Tar : obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void Invoke(ArchiveReader src, int index, ExtractDirectory dir)
Retry(() => src.Save(Temp, item, GetProgress()));

var dest = Io.Combine(Temp, item.FullName);
if (FormatDetector.From(dest) != Format.Tar) Move(item);
if (FormatFactory.From(dest) != Format.Tar) Move(item);
else
{
using var e = new ArchiveReader(dest, Password, src.Options);
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Core/Sources/ArchiveReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public ArchiveReader(string src, ArchiveOption options) : this(src, string.Empty
///
/* --------------------------------------------------------------------- */
public ArchiveReader(string src, string password, ArchiveOption options) :
this(FormatDetector.From(src), src, new(password), options) { }
this(FormatFactory.From(src), src, new(password), options) { }

/* --------------------------------------------------------------------- */
///
Expand All @@ -126,7 +126,7 @@ public ArchiveReader(string src, string password, ArchiveOption options) :
///
/* --------------------------------------------------------------------- */
public ArchiveReader(string src, IQuery<string> password, ArchiveOption options) :
this(FormatDetector.From(src), src, new(password), options) { }
this(FormatFactory.From(src), src, new(password), options) { }

/* --------------------------------------------------------------------- */
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ namespace Cube.FileSystem.SevenZip;

/* ------------------------------------------------------------------------- */
///
/// Formatter
/// FormatFactory
///
/// <summary>
/// Provides extended methods of the Format.
/// Provides functionality to detect the archive format with the specified
/// arguments.
/// </summary>
///
/* ------------------------------------------------------------------------- */
public static class FormatDetector
public static class FormatFactory
{
#region Methods

Expand Down
2 changes: 1 addition & 1 deletion Libraries/Core/Sources/Internal/ArchiveExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static string GetPath(this IInArchive src, int index, string path)
if (dest.HasValue()) return dest;

var tmp = Io.GetBaseName(path);
var fmt = FormatDetector.FromExtension(Io.GetExtension(tmp));
var fmt = FormatFactory.FromExtension(Io.GetExtension(tmp));
if (fmt != Format.Unknown) return Io.GetFileName(tmp);

var name = index == 0 ? Io.GetFileName(tmp) : $"{Io.GetFileName(tmp)}({index})";
Expand Down
2 changes: 1 addition & 1 deletion Tests/Core/Sources/ArchiveWriterExTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void WithCjk(CodePage cp)
}

using var ss = Io.Open(dest);
Assert.That(FormatDetector.From(ss), Is.EqualTo(zip));
Assert.That(FormatFactory.From(ss), Is.EqualTo(zip));
}

/* --------------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion Tests/Core/Sources/ArchiveWriterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Format Save(string filename, Format format, string[] src, CompressionOpti
obj.Clear();
}

using (var obj = Io.Open(dest)) return FormatDetector.From(obj);
using (var obj = Io.Open(dest)) return FormatFactory.From(obj);
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions Tests/Core/Sources/FormatTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public Format Detect(string filename)
{
var dest = Get(Guid.NewGuid().ToString("N"));
Io.Copy(GetSource(filename), dest, true);
return FormatDetector.From(dest);
return FormatFactory.From(dest);
}

/* --------------------------------------------------------------------- */
Expand Down Expand Up @@ -102,7 +102,7 @@ public Format Detect(string filename)
/* --------------------------------------------------------------------- */
[Test]
public void FromFile_NotFound()=> Assert.That(
FormatDetector.From(GetSource("NotFound.rar")),
FormatFactory.From(GetSource("NotFound.rar")),
Is.EqualTo(Format.Rar)
);

Expand Down

0 comments on commit 60064da

Please sign in to comment.