aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-10-14 16:12:07 -0700
committerRob Mensching <rob@firegiant.com>2017-10-14 16:12:07 -0700
commitdbde9e7104b907bbbaea17e21247d8cafc8b3a4c (patch)
tree0f5fbbb6fe12c6b2e5e622a0e18ce4c5b4eb2b96 /src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs
parentfbf986eb97f68396797a89fc7d40dec07b775440 (diff)
downloadwix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.tar.gz
wix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.tar.bz2
wix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.zip
Massive refactoring to introduce the concept of IBackend
Diffstat (limited to 'src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs')
-rw-r--r--src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs b/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs
index 0ecd0096..28fc4817 100644
--- a/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs
+++ b/src/WixToolset.Core/Bind/ExtractEmbeddedFiles.cs
@@ -1,6 +1,6 @@
1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. 1// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2 2
3namespace WixToolset.Bind 3namespace WixToolset.Core.Bind
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
@@ -13,11 +13,11 @@ namespace WixToolset.Bind
13 /// <summary> 13 /// <summary>
14 /// Internal helper class used to extract embedded files. 14 /// Internal helper class used to extract embedded files.
15 /// </summary> 15 /// </summary>
16 internal sealed class ExtractEmbeddedFiles 16 internal class ExtractEmbeddedFiles
17 { 17 {
18 private Dictionary<Uri, SortedList<int, string>> filesWithEmbeddedFiles = new Dictionary<Uri, SortedList<int, string>>(); 18 private Dictionary<Uri, SortedList<int, string>> filesWithEmbeddedFiles = new Dictionary<Uri, SortedList<int, string>>();
19 19
20 public IEnumerable<Uri> Uris { get { return this.filesWithEmbeddedFiles.Keys; } } 20 public IEnumerable<Uri> Uris => this.filesWithEmbeddedFiles.Keys;
21 21
22 /// <summary> 22 /// <summary>
23 /// Adds an embedded file index to track and returns the path where the embedded file will be extracted. Duplicates will return the same extract path. 23 /// Adds an embedded file index to track and returns the path where the embedded file will be extracted. Duplicates will return the same extract path.
@@ -53,15 +53,30 @@ namespace WixToolset.Bind
53 return extractPath; 53 return extractPath;
54 } 54 }
55 55
56 public IEnumerable<ExtractFile> GetExtractFilesForUri(Uri uri) 56 public IEnumerable<ExpectedExtractFile> GetExpectedEmbeddedFiles()
57 { 57 {
58 SortedList<int, string> extracts; 58 foreach (var uriWithExtracts in filesWithEmbeddedFiles)
59 if (!filesWithEmbeddedFiles.TryGetValue(uri, out extracts)) 59 {
60 foreach (var extracts in uriWithExtracts.Value)
61 {
62 yield return new ExpectedExtractFile
63 {
64 Uri = uriWithExtracts.Key,
65 EmbeddedFileIndex = extracts.Key,
66 OutputPath = extracts.Value,
67 };
68 }
69 }
70 }
71
72 public IEnumerable<ExpectedExtractFile> GetExtractFilesForUri(Uri uri)
73 {
74 if (!filesWithEmbeddedFiles.TryGetValue(uri, out var extracts))
60 { 75 {
61 extracts = new SortedList<int, string>(); 76 extracts = new SortedList<int, string>();
62 } 77 }
63 78
64 return extracts.Select(e => new ExtractFile() { EmbeddedFileIndex = e.Key, OutputPath = e.Value }); 79 return extracts.Select(e => new ExpectedExtractFile() { Uri = uri, EmbeddedFileIndex = e.Key, OutputPath = e.Value });
65 } 80 }
66 81
67 private string HashUri(string uri) 82 private string HashUri(string uri)
@@ -72,12 +87,5 @@ namespace WixToolset.Bind
72 return Convert.ToBase64String(hash).TrimEnd('=').Replace('+', '-').Replace('/', '_'); 87 return Convert.ToBase64String(hash).TrimEnd('=').Replace('+', '-').Replace('/', '_');
73 } 88 }
74 } 89 }
75
76 internal struct ExtractFile
77 {
78 public int EmbeddedFileIndex { get; set; }
79
80 public string OutputPath { get; set; }
81 }
82 } 90 }
83} 91}