Skip to content

Commit

Permalink
Merged development into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Tichau committed Oct 12, 2016
2 parents 4e3ce76 + a47ea62 commit ca9bdaf
Show file tree
Hide file tree
Showing 43 changed files with 1,398 additions and 173 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,7 @@ FakesAssemblies/
*.opt

# Ignore the installer signing commands file
Installer/Installer.sign
Installer/Installer.sign

# Ignore the installer languages file because it is automatically generated
Installer/Languages.wxs
21 changes: 16 additions & 5 deletions Application/FileConverter/Application.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public partial class Application : System.Windows.Application
private static readonly Version Version = new Version()
{
Major = 1,
Minor = 1,
Minor = 2,
Patch = 0,
};

Expand Down Expand Up @@ -341,8 +341,7 @@ private void Initialize()
{
string inputFilePath = filePaths[index];
ConversionJob conversionJob = ConversionJobFactory.Create(conversionPreset, inputFilePath);
conversionJob.PrepareConversion(inputFilePath);


this.conversionJobs.Add(conversionJob);
}
}
Expand All @@ -358,8 +357,14 @@ private void Initialize()

private void ConvertFiles()
{
Thread[] jobThreads = new Thread[this.numberOfConversionThread];
// Prepare conversions.
for (int index = 0; index < this.ConvertionJobs.Count; index++)
{
this.ConvertionJobs[index].PrepareConversion();
}

// Convert!
Thread[] jobThreads = new Thread[this.numberOfConversionThread];
while (true)
{
// Compute conversion flags.
Expand Down Expand Up @@ -396,7 +401,7 @@ private void ConvertFiles()
Thread thread = jobThreads[threadIndex];
if (thread == null || !thread.IsAlive)
{
jobThread = Helpers.InstantiateThread("ConversionThread", this.ExecuteConversionJob);
jobThread = Helpers.InstantiateThread(conversionJob.GetType().Name, this.ExecuteConversionJob);
jobThreads[threadIndex] = jobThread;
break;
}
Expand All @@ -405,6 +410,12 @@ private void ConvertFiles()
if (jobThread != null)
{
jobThread.Start(conversionJob);

while (conversionJob.State == ConversionJob.ConversionState.Ready)
{
Debug.Log("Wait the launch of the conversion thread before launching any other thread.");
Thread.Sleep(20);
}
}

break;
Expand Down
89 changes: 55 additions & 34 deletions Application/FileConverter/ConversionJobs/ConversionJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,32 @@ public class ConversionJob : INotifyPropertyChanged
private CancelConversionJobCommand cancelCommand;

private string initialInputPath = string.Empty;
private string[] outputFilePaths;
private int currentOuputFilePathIndex;

public ConversionJob()
{
this.State = ConversionState.Unknown;
this.ConversionPreset = null;
this.initialInputPath = string.Empty;
this.InputFilePath = string.Empty;
}

public ConversionJob(ConversionPreset conversionPreset) : this()
public ConversionJob(ConversionPreset conversionPreset, string inputFilePath) : this()
{
if (conversionPreset == null)
{
throw new ArgumentNullException("conversionPreset");
throw new ArgumentNullException(nameof(conversionPreset));
}

if (string.IsNullOrEmpty(inputFilePath))
{
throw new ArgumentNullException(nameof(inputFilePath));
}

this.initialInputPath = inputFilePath;
this.InputFilePath = inputFilePath;
this.ConversionPreset = conversionPreset;
this.UserState = Properties.Resources.ConversionStatePrepareConversion;
}

public event PropertyChangedEventHandler PropertyChanged;
Expand Down Expand Up @@ -67,22 +75,22 @@ public string OutputFilePath
{
get
{
if (this.outputFilePaths == null)
if (this.OutputFilePaths == null || this.OutputFilePaths.Length == 0)
{
return string.Empty;
}

if (this.CurrentOuputFilePathIndex < 0)
{
return this.outputFilePaths[0];
return this.OutputFilePaths[0];
}

if (this.CurrentOuputFilePathIndex >= this.outputFilePaths.Length)
if (this.CurrentOuputFilePathIndex >= this.OutputFilePaths.Length)
{
return this.outputFilePaths[this.outputFilePaths.Length - 1];
return this.OutputFilePaths[this.OutputFilePaths.Length - 1];
}

return this.outputFilePaths[this.CurrentOuputFilePathIndex];
return this.OutputFilePaths[this.CurrentOuputFilePathIndex];
}
}

Expand Down Expand Up @@ -200,24 +208,27 @@ protected virtual InputPostConversionAction InputPostConversionAction
}
}

protected string[] OutputFilePaths
{
get;
private set;
}

public virtual bool CanStartConversion(ConversionFlags conversionFlags)
{
return (conversionFlags & ConversionFlags.CdDriveExtraction) == 0;
}

public void PrepareConversion(string inputFilePath, string outputFilePath = null)
public void PrepareConversion(params string[] outputFilePaths)
{
if (string.IsNullOrEmpty(inputFilePath))
{
throw new ArgumentNullException(nameof(inputFilePath));
}

if (this.ConversionPreset == null)
{
throw new Exception("The conversion preset must be valid.");
}

string extension = System.IO.Path.GetExtension(inputFilePath);
this.InputFilePath = this.initialInputPath;

string extension = System.IO.Path.GetExtension(this.initialInputPath);
extension = extension.Substring(1, extension.Length - 1);
string extensionCategory = Helpers.GetExtensionCategory(extension);
if (!Helpers.IsOutputTypeCompatibleWithCategory(this.ConversionPreset.OutputType, extensionCategory))
Expand All @@ -226,15 +237,22 @@ public void PrepareConversion(string inputFilePath, string outputFilePath = null
return;
}

this.initialInputPath = inputFilePath;
this.InputFilePath = inputFilePath;

int outputFilesCount = this.GetOuputFilesCount();
this.outputFilePaths = new string[outputFilesCount];
this.OutputFilePaths = outputFilePaths;
if (this.OutputFilePaths.Length == 0)
{
int outputFilesCount = this.GetOuputFilesCount();
this.OutputFilePaths = new string[outputFilesCount];
}

for (int index = 0; index < outputFilesCount; index++)
for (int index = 0; index < this.OutputFilePaths.Length; index++)
{
string path = outputFilePath ?? this.ConversionPreset.GenerateOutputFilePath(inputFilePath, index + 1, outputFilesCount);
if (!string.IsNullOrEmpty(this.OutputFilePaths[index]))
{
// Don't generate a path if it has already been set.
continue;
}

string path = this.ConversionPreset.GenerateOutputFilePath(this.initialInputPath, index + 1, this.OutputFilePaths.Length);

if (!PathHelpers.IsPathValid(path))
{
Expand All @@ -252,7 +270,7 @@ public void PrepareConversion(string inputFilePath, string outputFilePath = null
string inputExtension = System.IO.Path.GetExtension(this.InputFilePath);
string pathWithoutExtension = this.InputFilePath.Substring(0, this.InputFilePath.Length - inputExtension.Length);
this.InputFilePath = PathHelpers.GenerateUniquePath(pathWithoutExtension + "_TEMP" + inputExtension);
System.IO.File.Move(inputFilePath, this.InputFilePath);
System.IO.File.Move(this.initialInputPath, this.InputFilePath);
}
}

Expand All @@ -266,7 +284,7 @@ public void PrepareConversion(string inputFilePath, string outputFilePath = null
// Make the output path valid.
try
{
path = PathHelpers.GenerateUniquePath(path, this.outputFilePaths);
path = PathHelpers.GenerateUniquePath(path, this.OutputFilePaths);
}
catch (Exception exception)
{
Expand All @@ -275,7 +293,7 @@ public void PrepareConversion(string inputFilePath, string outputFilePath = null
return;
}

this.outputFilePaths[index] = path;
this.OutputFilePaths[index] = path;
}

this.CurrentOuputFilePathIndex = 0;
Expand All @@ -295,7 +313,10 @@ public void PrepareConversion(string inputFilePath, string outputFilePath = null

Debug.Log("Job initialized: Preset: '{0}' Input: {1} Output: {2}", this.ConversionPreset.Name, this.InputFilePath, this.OutputFilePath);

this.UserState = Properties.Resources.ConversionStateInQueue;
if (this.State != ConversionState.Failed)
{
this.UserState = Properties.Resources.ConversionStateInQueue;
}
}

public void StartConvertion()
Expand Down Expand Up @@ -336,11 +357,11 @@ public void StartConvertion()

if (this.State == ConversionJob.ConversionState.Done && !this.AllOuputFilesExists())
{
Debug.LogError("Can't find the output file(s).");
Debug.LogError(Properties.Resources.ErrorCantFindOutputFiles);
}
else if (this.State == ConversionJob.ConversionState.Failed && this.AtLeastOneOuputFilesExists())
{
Debug.Log("The conversion job failed but there is an output file that does exists.");
Debug.Log(Properties.Resources.ErrorConversionFailedWithOutput);
}
}

Expand Down Expand Up @@ -372,9 +393,9 @@ protected virtual void OnConversionFailed()
{
Debug.Log("Conversion Failed.");

for (int index = 0; index < this.outputFilePaths.Length; index++)
for (int index = 0; index < this.OutputFilePaths.Length; index++)
{
string outputFilePath = this.outputFilePaths[index];
string outputFilePath = this.OutputFilePaths[index];
try
{
if (System.IO.File.Exists(outputFilePath))
Expand Down Expand Up @@ -453,9 +474,9 @@ protected void NotifyPropertyChanged([CallerMemberName] string propertyName = ""

private bool AllOuputFilesExists()
{
for (int index = 0; index < this.outputFilePaths.Length; index++)
for (int index = 0; index < this.OutputFilePaths.Length; index++)
{
string outputFilePath = this.outputFilePaths[index];
string outputFilePath = this.OutputFilePaths[index];
if (!System.IO.File.Exists(outputFilePath))
{
return false;
Expand All @@ -467,9 +488,9 @@ private bool AllOuputFilesExists()

private bool AtLeastOneOuputFilesExists()
{
for (int index = 0; index < this.outputFilePaths.Length; index++)
for (int index = 0; index < this.OutputFilePaths.Length; index++)
{
string outputFilePath = this.outputFilePaths[index];
string outputFilePath = this.OutputFilePaths[index];
if (System.IO.File.Exists(outputFilePath))
{
return true;
Expand Down
35 changes: 25 additions & 10 deletions Application/FileConverter/ConversionJobs/ConversionJobFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,46 @@ public static ConversionJob Create(ConversionPreset conversionPreset, string inp
inputFileExtension = inputFileExtension.ToLowerInvariant().Substring(1, inputFileExtension.Length - 1);
if (inputFileExtension == "cda")
{
return new ConversionJob_ExtractCDA(conversionPreset);
return new ConversionJob_ExtractCDA(conversionPreset, inputFilePath);
}

if (conversionPreset.OutputType == OutputType.Ico)
if (inputFileExtension == "docx" || inputFileExtension == "odt" || inputFileExtension == "doc")
{
return new ConversionJob_Ico(conversionPreset);
return new ConversionJob_Word(conversionPreset, inputFilePath);
}

if (conversionPreset.OutputType == OutputType.Gif)
if (inputFileExtension == "xlsx" || inputFileExtension == "ods" || inputFileExtension == "xls")
{
return new ConversionJob_Gif(conversionPreset);
return new ConversionJob_Excel(conversionPreset, inputFilePath);
}

if (Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Image ||
Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Document)
if (inputFileExtension == "pptx" || inputFileExtension == "odp" || inputFileExtension == "ppt")
{
return new ConversionJob_PowerPoint(conversionPreset, inputFilePath);
}

if (conversionPreset.OutputType == OutputType.Ico)
{
return new ConversionJob_ImageMagick(conversionPreset);
return new ConversionJob_Ico(conversionPreset, inputFilePath);
}

if (conversionPreset.OutputType == OutputType.Gif)
{
return new ConversionJob_Gif(conversionPreset, inputFilePath);
}

if (conversionPreset.OutputType == OutputType.Pdf)
{
return new ConversionJob_ImageMagick(conversionPreset);
return new ConversionJob_ImageMagick(conversionPreset, inputFilePath);
}

return new ConversionJob_FFMPEG(conversionPreset);
if (Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Image ||
Helpers.GetExtensionCategory(inputFileExtension) == Helpers.InputCategoryNames.Document)
{
return new ConversionJob_ImageMagick(conversionPreset, inputFilePath);
}

return new ConversionJob_FFMPEG(conversionPreset, inputFilePath);
}
}
}
Loading

0 comments on commit ca9bdaf

Please sign in to comment.