Skip to content

Commit

Permalink
Compressor is now skipping unresolvable files and logs a warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ConstantinRuhdorfer committed May 10, 2019
1 parent c855f63 commit 53d735f
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions src/Gsd2Aml.Lib/Compressor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,25 @@ public static void Compress(string amlFilePath, string destination, string[] res
foreach (var resource in resources)
{
var fileName = Path.GetFileName(resource);
if (!string.IsNullOrEmpty(fileName)) CopyFile(resource, Path.Combine(tmpPath, fileName));
else throw new IOException($"Resource filename unexpectedly null or empty");
if (string.IsNullOrEmpty(fileName))
{
Converter.Logger?.Log(LogLevel.Warning, "While copying a null or empty filename was found - skipping.");
}
else
{
try
{
CopyFile(resource, Path.Combine(tmpPath, fileName));
}
catch (FileNotFoundException)
{
Converter.Logger?.Log(LogLevel.Warning, $"While trying to copy {fileName} the file was not found - skipping.");
}
catch (DirectoryNotFoundException)
{
Converter.Logger?.Log(LogLevel.Warning, $"While trying to copy {resource} the directory was not found - skipping.");
}
}
}

if (!string.IsNullOrEmpty(amlFileName)) CopyFile(amlFilePath, amlFileTmpPath);
Expand Down Expand Up @@ -99,11 +116,10 @@ private static void Zip(string sourceAml, string destination, IEnumerable<string
var fileName = Path.GetFileName(resource);
if (string.IsNullOrEmpty(fileName)) continue;
var fileTmpPath = Path.Combine(Path.GetTempPath(), Gsd2AmlName, fileName);
if (!File.Exists(fileTmpPath)) continue;
var fileUri = new Uri("/" + fileName, UriKind.Relative);
ac.AddAnyContent(root, fileTmpPath, fileUri);

}

ac.Close();
}
}
Expand Down Expand Up @@ -171,6 +187,14 @@ private static void CopyFile(string source, string destination)
{
File.Copy(source, destination, true);
}
catch (FileNotFoundException)
{
throw;
}
catch (DirectoryNotFoundException)
{
throw;
}
catch (PathTooLongException e)
{
throw new PathTooLongException("Could not copy the file because a path was too long.", e);
Expand Down

0 comments on commit 53d735f

Please sign in to comment.