Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Orc.SupportPackage.Example/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ protected override void OnStartup(StartupEventArgs e)

this.ApplyTheme();

Globals.EnableEncryption = true;

base.OnStartup(e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ namespace Orc.SupportPackage

public class SupportPackageBuilderService : ISupportPackageBuilderService
{
private const int DirectorySizeLimitInBytes = 25 * 1024 * 1024;

#region Fields
private static readonly ILog Log = LogManager.GetCurrentClassLogger();

Expand Down Expand Up @@ -61,7 +59,9 @@ public virtual async Task<bool> CreateSupportPackageAsync(string fileName, List<
}

var excludeFileNamePatterns = artifacts.Where(artifact => !artifact.IncludeInSupportPackage).OfType<SupportPackageFileNamePattern>().SelectMany(artifact => artifact.FileNamePatterns).Distinct().ToArray();
var directories = artifacts.Where(artifact => artifact.IncludeInSupportPackage).OfType<SupportPackageDirectory>().Select(artifact => artifact.DirectoryName).Distinct().ToArray();
var directories = artifacts.Where(artifact => artifact.IncludeInSupportPackage).OfType<SupportPackageDirectory>().Select(artifact => artifact.DirectoryName)
.Distinct()
.ToArray();

builder.AppendLine();
builder.AppendLine("## Exclude file name patterns");
Expand All @@ -81,81 +81,25 @@ public virtual async Task<bool> CreateSupportPackageAsync(string fileName, List<
builder.AppendLine("- " + directory);
}

var result = await _supportPackageService.CreateSupportPackageAsync(fileName, directories, excludeFileNamePatterns);

var customDataDirectoryName = "CustomData";
using (var fileStream = new FileStream(fileName, FileMode.OpenOrCreate))
var customData = artifacts.Where(artifact => artifact.IncludeInSupportPackage).OfType<CustomPathsPackageFileSystemArtifact>().SelectMany(x => x.Paths);
if (customData.Any())
{
using (var zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Update))
{
foreach (var artifact in artifacts.OfType<CustomPathsPackageFileSystemArtifact>().Where(artifact => artifact.IncludeInSupportPackage))
{
builder.AppendLine();
builder.AppendLine("## Include custom data");
builder.AppendLine();

foreach (var path in artifact.Paths)
{
try
{
var directoryInfo = new DirectoryInfo(path);
if (directoryInfo.Exists)
{
var directorySize = directoryInfo.GetFiles("*.*", SearchOption.AllDirectories).Sum(info => info.Length);
if (directorySize > DirectorySizeLimitInBytes)
{
Log.Info("Skipped directory '{0}' beacuse its size is greater than '{1}' bytes", path, DirectorySizeLimitInBytes);

builder.AppendLine("- Directory (skipped): " + path);
}
else
{
zipArchive.CreateEntryFromDirectory(path, Path.Combine(customDataDirectoryName, directoryInfo.Name), CompressionLevel.Optimal);
builder.AppendLine("- Directory: " + path);
}
}
}
catch (Exception ex)
{
Log.Warning(ex);
}

try
{
if (_fileService.Exists(path))
{
zipArchive.CreateEntryFromAny(path, customDataDirectoryName, CompressionLevel.Optimal);
builder.AppendLine("- File: " + path);
}
}
catch (Exception ex)
{
Log.Warning(ex);
}
}
}

builder.AppendLine();
builder.AppendLine("## File system entries");
builder.AppendLine();
builder.AppendLine("- Total: " + zipArchive.Entries.Count);
builder.AppendLine("- Files: " + zipArchive.Entries.Count(entry => !entry.Name.EndsWith("/")));
builder.AppendLine("- Directories: " + zipArchive.Entries.Count(entry => entry.Name.EndsWith("/")));

var builderEntry = zipArchive.CreateEntry("SupportPackageOptions.txt");

using (var streamWriter = new StreamWriter(builderEntry.Open()))
{
await streamWriter.WriteAsync(builder.ToString());
}

await fileStream.FlushAsync();
}
builder.AppendLine();
builder.AppendLine("## Include custom data");
builder.AppendLine();
}

var result = await _supportPackageService.CreateSupportPackageAsync(fileName, directories, excludeFileNamePatterns, new SupportPackageOptions
{
FileSystemPaths = customData.ToArray(),
DescriptionBuilder = builder
});

return result;
}



#endregion
}
}
20 changes: 19 additions & 1 deletion src/Orc.SupportPackage/Context/SupportPackageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Orc.SupportPackage
{
using System;
using System.Collections.Generic;
using System.IO;
using Catel;
using Catel.Logging;
Expand All @@ -19,6 +20,9 @@ public class SupportPackageContext : Disposable, ISupportPackageContext

private readonly string _rootDirectory;

private readonly List<string> _artifactsDirectories = new();
private readonly List<string> _excludefileNamePatterns = new();

public SupportPackageContext()
{
var assembly = AssemblyHelper.GetEntryAssembly();
Expand All @@ -29,7 +33,11 @@ public SupportPackageContext()
Directory.CreateDirectory(_rootDirectory);
}

public string RootDirectory { get { return _rootDirectory; } }
public string RootDirectory => _rootDirectory;

public IReadOnlyCollection<string> ExcludeFileNamePatterns => _excludefileNamePatterns;

public IReadOnlyCollection<string> ArtifactsDirectories => _artifactsDirectories;

public string GetDirectory(string relativeDirectoryName)
{
Expand All @@ -56,6 +64,16 @@ public string GetFile(string relativeFilePath)
return fullPath;
}

public void AddArtifactDirectories(string[] directories)
{
_artifactsDirectories.AddRange(directories);
}

public void AddExcludeFileNamePatterns(string[] fileNamePatterns)
{
_excludefileNamePatterns.AddRange(fileNamePatterns);
}

protected override void DisposeManaged()
{
Log.Info("Deleting temporary files from '{0}'", _rootDirectory);
Expand Down
45 changes: 45 additions & 0 deletions src/Orc.SupportPackage/Cryptography/EncryptionContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace Orc.SupportPackage
{
using System;
using Catel;

public class EncryptionContext
{
public EncryptionContext()
{

}

public EncryptionContext(EncryptionContext context)
{
Argument.IsNotNull(() => context);

PassPhrase = context.PassPhrase;
SaltValue = context.SaltValue;
PasswordIterations = context.PasswordIterations;
InitVector = context.InitVector;
KeySize = context.KeySize;
}

public EncryptionContext(string passPhrase, string saltValue, int? passwordIterations, string initVector, int? keySize)
{
PassPhrase = passPhrase;
SaltValue = saltValue;
PasswordIterations = passwordIterations;
InitVector = initVector;
KeySize = keySize;
}

public string PassPhrase { get; set; }

public string SaltValue { get; set; }

public int? PasswordIterations { get; set; }

public string InitVector { get; set; }

public int? KeySize { get; set; }

public IProgress<long> Progress { get; set; }
}
}
Loading