Skip to content

Commit 8319e69

Browse files
Update v1.6.1
1 parent 3accaff commit 8319e69

7 files changed

Lines changed: 164 additions & 11 deletions

File tree

Changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Change Log
22

3+
## v1.6.1
4+
5+
Release Date: **05.10.2020**
6+
7+
- Fixed a bug in the preview-handling of embedded plain text files
8+
- Fixed a general bug in the handling of archive files (no office or zip files)
9+
10+
---
11+
312
## v1.6.0
413

514
Release Date: **04.10.2020**

MediaExtractor/App.config

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<configuration>
33
<configSections>
4-
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5-
<section name="MediaExtractor.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
4+
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
5+
<section name="MediaExtractor.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
66
</sectionGroup>
7-
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
8-
<section name="MediaExtractor.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
7+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
8+
<section name="MediaExtractor.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
99
</sectionGroup>
1010
</configSections>
1111
<applicationSettings>
@@ -39,7 +39,7 @@
3939
<value>False</value>
4040
</setting>
4141
<setting name="Locale" serializeAs="String">
42-
<value />
42+
<value/>
4343
</setting>
4444
<setting name="ExtractSaveAll" serializeAs="String">
4545
<value>False</value>
@@ -58,4 +58,4 @@
5858
</setting>
5959
</MediaExtractor.Properties.Settings>
6060
</userSettings>
61-
</configuration>
61+
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>

MediaExtractor/ArchiveResolver.cs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
* Media Extractor is an application to preview and extract packed media in Microsoft Office files (e.g. Word, PowerPoint or Excel documents)
3+
* Copyright Raphael Stoeckli © 2020
4+
* This program is licensed under the MIT License.
5+
* You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
6+
*/
7+
8+
using SevenZipExtractor;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.IO;
12+
13+
namespace MediaExtractor
14+
{
15+
/// <summary>
16+
/// Class to resolve archives either by the file name or the stream (guessed)
17+
/// </summary>
18+
public static class ArchiveResolver
19+
{
20+
21+
private static Dictionary<string, SevenZipFormat> archiveFormats = null;
22+
23+
/// <summary>
24+
/// Dictionary of supported archive formats
25+
/// </summary>
26+
public static Dictionary<string, SevenZipFormat> ArchiveFormats
27+
{
28+
get
29+
{
30+
if (archiveFormats == null)
31+
{
32+
GetFormats();
33+
}
34+
return archiveFormats;
35+
}
36+
}
37+
38+
/// <summary>
39+
/// Singleton initializer to get the supported archive formats
40+
/// </summary>
41+
private static void GetFormats()
42+
{
43+
SevenZipFormat[] formats = Enum.GetValues(typeof(SevenZipFormat)) as SevenZipFormat[];
44+
archiveFormats = new Dictionary<string, SevenZipFormat>(formats.Length);
45+
foreach (SevenZipFormat format in formats)
46+
{
47+
archiveFormats.Add(Enum.GetName(typeof(SevenZipFormat), format).ToLower(), format);
48+
}
49+
}
50+
51+
/// <summary>
52+
/// Method to open an archive, initially by its file extension
53+
/// </summary>
54+
/// <param name="stream">Memory stream of the archive</param>
55+
/// <param name="extension">File extension of the archive</param>
56+
/// <returns></returns>
57+
public static ArchiveFile Open(MemoryStream stream, string extension)
58+
{
59+
ArchiveFile archive;
60+
string error;
61+
if (ArchiveFormats.ContainsKey(extension.ToLower()))
62+
{
63+
if (OpenArchive(ref stream, ArchiveFormats[extension.ToLower()], out archive, out error))
64+
{
65+
return archive;
66+
}
67+
}
68+
if (TryOpen(ref stream, out archive, out error))
69+
{
70+
return archive;
71+
}
72+
else
73+
{
74+
throw new IOException(error);
75+
}
76+
}
77+
78+
/// <summary>
79+
/// Method to try opening an archive without defined format
80+
/// </summary>
81+
/// <param name="stream">Memory stream of the archive</param>
82+
/// <param name="archive">Opened archive as out parameter. May be null in case of an error</param>
83+
/// <param name="error">Error message. May be empty, if no error occurred</param>
84+
/// <returns>True if the extraction was successful, otherwise false</returns>
85+
private static bool TryOpen(ref MemoryStream stream, out ArchiveFile archive, out string error)
86+
{
87+
ArchiveFile arch;
88+
string err;
89+
if (OpenArchive(ref stream, SevenZipFormat.Zip, out arch, out err))
90+
{
91+
archive = arch;
92+
error = string.Empty;
93+
return true;
94+
}
95+
foreach (KeyValuePair<string, SevenZipFormat> format in ArchiveFormats)
96+
{
97+
if (format.Value == SevenZipFormat.Zip)
98+
{
99+
continue; // Already checked
100+
}
101+
if (OpenArchive(ref stream, format.Value, out arch, out err))
102+
{
103+
archive = arch;
104+
error = string.Empty;
105+
return true;
106+
}
107+
}
108+
error = err;
109+
archive = null;
110+
return false;
111+
}
112+
113+
/// <summary>
114+
/// Method to try opening an archive, based on an archive type
115+
/// </summary>
116+
/// <param name="stream">Memory stream of the archive</param>
117+
/// <param name="format">Predefined archive format</param>
118+
/// <param name="archive">Opened archive as out parameter. May be null in case of an error</param>
119+
/// <param name="error">Error message. May be empty, if no error occurred</param>
120+
/// <returns>True if the extraction was successful, otherwise false</returns>
121+
private static bool OpenArchive(ref MemoryStream stream, SevenZipFormat format, out ArchiveFile archive, out string error)
122+
{
123+
try
124+
{
125+
archive = new ArchiveFile(stream, format);
126+
error = string.Empty;
127+
return true;
128+
}
129+
catch (Exception ex)
130+
{
131+
archive = null;
132+
stream.Position = 0;
133+
error = ex.Message;
134+
return false;
135+
}
136+
}
137+
138+
}
139+
}

MediaExtractor/Extractor.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* You find a copy of the license in project folder or on: http://opensource.org/licenses/MIT
66
*/
77

8+
9+
810
using SevenZipExtractor;
911
using System;
1012
using System.Collections.Generic;
@@ -79,10 +81,12 @@ public void ResetErrors()
7981
/// </summary>
8082
public void Extract()
8183
{
84+
8285
try
8386
{
87+
FileInfo fi = new FileInfo(FileName);
8488
MemoryStream ms = GetFileStream();
85-
ArchiveFile ex = new ArchiveFile(ms, SevenZipFormat.Zip);
89+
ArchiveFile ex = ArchiveResolver.Open(ms, fi.Extension.ToLower().TrimStart('.'));
8690
embeddedFiles = GetEntries(ref ex);
8791
currentModel.NumberOfFiles = embeddedFiles.Count;
8892
for (int i = 0; i < currentModel.NumberOfFiles; i++)

MediaExtractor/ExtractorItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void CreateXml()
203203
/// </summary>
204204
public void CreateText()
205205
{
206-
ValidImage = Preview.CreateText(Stream, out genericText, out errorMessage);
206+
ValidGenericText = Preview.CreateText(Stream, out genericText, out errorMessage);
207207
initialized = true;
208208
}
209209

MediaExtractor/MediaExtractor.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<Compile Include="About.xaml.cs">
103103
<DependentUpon>About.xaml</DependentUpon>
104104
</Compile>
105+
<Compile Include="ArchiveResolver.cs" />
105106
<Compile Include="CommandHandler.cs" />
106107
<Compile Include="ExistingFileDialog.xaml.cs">
107108
<DependentUpon>ExistingFileDialog.xaml</DependentUpon>

MediaExtractor/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222

2323

2424
// [assembly: AssemblyVersion("1.0.*")]
25-
[assembly: AssemblyVersion("1.6.0.0")]
26-
[assembly: AssemblyFileVersion("1.6.0.0")]
25+
[assembly: AssemblyVersion("1.6.1.0")]
26+
[assembly: AssemblyFileVersion("1.6.1.0")]

0 commit comments

Comments
 (0)