Skip to content

Commit

Permalink
Merge pull request #23 from caraplana1/dev
Browse files Browse the repository at this point in the history
2.2.0 IS OUT!!!
  • Loading branch information
caraplana1 authored Aug 4, 2024
2 parents b94eb4a + 73ed0b9 commit 16fbcaa
Show file tree
Hide file tree
Showing 21 changed files with 637 additions and 472 deletions.
81 changes: 81 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,84 @@ $RECYCLE.BIN/
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### Rider ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# End of https://www.toptal.com/developers/gitignore/api/rider
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

18 changes: 10 additions & 8 deletions ComicConverter.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
# Visual Studio Version 17
VisualStudioVersion = 17.10.34916.146
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComicConverter", "ComicConverter\ComicConverter.csproj", "{0CB8A9CB-D407-429D-A61A-206B9417CF6A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComicConverter", "ComicConverter\ComicConverter.csproj", "{0CB8A9CB-D407-429D-A61A-206B9417CF6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{3D97E45C-B295-4E6A-973D-EFA26F51F00C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{3D97E45C-B295-4E6A-973D-EFA26F51F00C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -16,9 +16,6 @@ Global
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0CB8A9CB-D407-429D-A61A-206B9417CF6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CB8A9CB-D407-429D-A61A-206B9417CF6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand All @@ -39,10 +36,15 @@ Global
{3D97E45C-B295-4E6A-973D-EFA26F51F00C}.Debug|x86.ActiveCfg = Debug|Any CPU
{3D97E45C-B295-4E6A-973D-EFA26F51F00C}.Debug|x86.Build.0 = Debug|Any CPU
{3D97E45C-B295-4E6A-973D-EFA26F51F00C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D97E45C-B295-4E6A-973D-EFA26F51F00C}.Release|Any CPU.Build.0 = Release|Any CPU
{3D97E45C-B295-4E6A-973D-EFA26F51F00C}.Release|x64.ActiveCfg = Release|Any CPU
{3D97E45C-B295-4E6A-973D-EFA26F51F00C}.Release|x64.Build.0 = Release|Any CPU
{3D97E45C-B295-4E6A-973D-EFA26F51F00C}.Release|x86.ActiveCfg = Release|Any CPU
{3D97E45C-B295-4E6A-973D-EFA26F51F00C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B18D5FA5-7DD6-4A69-B2F8-2E248C998720}
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions ComicConverter.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeEditing/SuppressNullableWarningFix/Enabled/@EntryValue">False</s:Boolean></wpf:ResourceDictionary>
91 changes: 31 additions & 60 deletions ComicConverter/Comic.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.IO;
using ComicConverter.Enums;
using SharpCompress.Archives.Rar;
using SharpCompress.Archives.Zip;
using SharpCompress.Archives.Tar;
using SharpCompress.Archives.SevenZip;

namespace ComicConverter
{
Expand All @@ -18,13 +18,13 @@ public class Comic
/// Comic File direction.
/// </summary>
/// <value>String</value>
public string Path { get; }
private string Path { get; }

/// <summary>
/// The given comic's format enum.
/// Comic's format enum.
/// </summary>
/// <value>Enum</value>
public ComicFormat Format { get; }
private ComicFormat Format { get; }

#endregion

Expand All @@ -42,22 +42,6 @@ public Comic(string comicPath)
Format = FindComicFormat();
}

/// <summary>
/// Constructor
/// </summary>
/// <param name="comicPath">Direction of the comic file.</param>
/// <param name="format">Specify the format</param>
/// <exception cref="FileNotFoundException"></exception>
public Comic(string comicPath, ComicFormat format)
{
if (!File.Exists(comicPath))
throw new FileNotFoundException();
else
Path = comicPath;

Format = format;
}

/// <summary>
/// Convert the file to the given format.
/// </summary>
Expand All @@ -69,15 +53,15 @@ public void Convert(string outputPath, ComicFormat format)
if (!IsValidOutputFormat(format))
throw new FormatException($"Can't convert comic to {format}");

DirectoryInfo dir = Directory.CreateDirectory(".ConvertedImagesHiddenDir");
var dir = Directory.CreateDirectory(".ConvertedImagesHiddenDir");
dir.Attributes = FileAttributes.Hidden | FileAttributes.Directory;

var ExtractImages = FindExtractorImageAction(Format);
var BuildComic = FindComicBuilderAction(format);
var extractImages = FindExtractorImageAction(Format);
var buildComic = FindComicBuilderAction(format);

ExtractImages(Path, dir.Name);
extractImages(Path, dir.Name);

BuildComic(Directory.GetFiles(dir.Name), outputPath);
buildComic(Directory.GetFiles(dir.Name), outputPath);

dir.Delete(true);
}
Expand All @@ -89,15 +73,13 @@ public void Convert(string outputPath, ComicFormat format)
private ComicFormat FindComicFormat()
{
if (RarArchive.IsRarFile(Path))
return ComicFormat.CBR;
return ComicFormat.Cbr;
if (ZipArchive.IsZipFile(Path))
return ComicFormat.CBZ;
return ComicFormat.Cbz;
if (TarArchive.IsTarFile(Path))
return ComicFormat.CBT;
if (SevenZipArchive.IsSevenZipFile(Path))
return ComicFormat.CB7;
if (IsValidPDF())
return ComicFormat.PDF;
return ComicFormat.Cbt;
if (IsValidPdf())
return ComicFormat.Pdf;

throw new FormatException("File is not in proper format");
}
Expand All @@ -106,64 +88,53 @@ private ComicFormat FindComicFormat()
/// Verify if the comic file PDF encrypted
/// </summary>
/// <returns>True if it is a valid pdf, false otherwise</returns>
private bool IsValidPDF()
private bool IsValidPdf()
{
StreamReader file = new(Path);
string firstLine = file.ReadLine().Substring(0, 7);
var firstLine = file.ReadLine()?.Substring(0, 8);
file.Close();

if (firstLine == "%PDF-1.")
return true;
else
return false;
return firstLine is "%PDF-1.4" or "%PDF-1.5";
}

/// <summary>
/// Verify is the output format to convert is suported.
/// Verify is the output format to convert is supported.
/// </summary>
/// <param name="format">Format enum to compare</param>
/// <returns>True if it's valid false otherwise.</returns>
private bool IsValidOutputFormat(ComicFormat format)
{
if (format == ComicFormat.CBZ)
return true;
if (format == ComicFormat.CBT)
return true;
if (format == ComicFormat.PDF)
return true;

return false;
}
private static bool IsValidOutputFormat(ComicFormat format)
=> format is ComicFormat.Cbz or ComicFormat.Cbt or ComicFormat.Pdf;


/// <summary>
/// Find the correct method to extract images from the supported file given an format.
/// Find the correct method to extract images from the supported file given a format.
/// </summary>
/// <param name="format">The format of the file to extract images.</param>
/// <returns>The correct method to extract image to the correct format file.</returns>
private Action<string, string> FindExtractorImageAction(ComicFormat format)
{
return format switch
{
ComicFormat.CBR => ImageExtractors.UnRar,
ComicFormat.CBZ => ImageExtractors.UnZip,
ComicFormat.CBT => ImageExtractors.UnTar,
ComicFormat.CB7 => ImageExtractors.UnSevenZip,
ComicFormat.PDF => ImageExtractors.ExtractPdfImages,
ComicFormat.Cbr => ImageExporter.UnRar,
ComicFormat.Cbz => ImageExporter.UnZip,
ComicFormat.Cbt => ImageExporter.UnTar,
ComicFormat.Pdf => ImageExporter.ExportPdfImages,
_ => throw new FormatException(),
};
}

/// <summary>
/// Find the correct Method to created a comic in the given supproted format.
/// Find the correct Method to create a comic in the given supported format.
/// </summary>
/// <param name="format">The end format of the file to create</param>
/// <returns>The Method to transform the images to a supported comic file.</returns>
private Action<string[], string> FindComicBuilderAction(ComicFormat format)
{
return format switch
{
ComicFormat.CBZ => ComicBuilder.CreateCBZ,
ComicFormat.CBT => ComicBuilder.CreateCBT,
ComicFormat.PDF => ComicBuilder.CreatePdf,
ComicFormat.Cbz => ComicBuilder.CreateCbz,
ComicFormat.Cbt => ComicBuilder.CreateCbt,
ComicFormat.Pdf => ComicBuilder.CreatePdf,
_ => throw new FormatException(),
};
}
Expand Down
Loading

0 comments on commit 16fbcaa

Please sign in to comment.