Skip to content

Commit 2cece69

Browse files
Update v1.5.0
1 parent 6d5e241 commit 2cece69

13 files changed

Lines changed: 559 additions & 146 deletions

MediaExtractor/App.config

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@
4141
<setting name="Locale" serializeAs="String">
4242
<value />
4343
</setting>
44+
<setting name="ExtractSaveAll" serializeAs="String">
45+
<value>False</value>
46+
</setting>
47+
<setting name="ExtractSaveSelected" serializeAs="String">
48+
<value>False</value>
49+
</setting>
50+
<setting name="ImageExtensions" serializeAs="String">
51+
<value>jpg,jpeg,png,wmf,emf,gif,bmp,ico,wdp</value>
52+
</setting>
53+
<setting name="TextExtensions" serializeAs="String">
54+
<value>asc,bas,bat,c,cfg,cmd,cpp,cs,css,csv,h,hex,htm,html,inc,inf,info,ini,java,js,json,kt,ktm,kts,latex,less,lisp,log,lst,lua,markdown,md,me,meta,mf,p,pas,php,pl,pp,ps,ps1,psm1,py,r,rb,readme,reg,rs,rst,sh,sln,sql,sty,tcl,tex,ts,tsx,txt,vb,vba,vbs,yaml,yml</value>
55+
</setting>
56+
<setting name="XmlExtensions" serializeAs="String">
57+
<value>xml,manifest,rels,xhtml,xaml,svg,pom,dtd,xsd,x3d,collada,cdxml,config,nuspec,graphml</value>
58+
</setting>
4459
</MediaExtractor.Properties.Settings>
4560
</userSettings>
4661
</configuration>

MediaExtractor/ExtractorItem.cs

Lines changed: 69 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Collections.Generic;
1010
using System.Drawing.Imaging;
1111
using System.IO;
12+
using System.Linq;
1213
using System.Text;
1314
using System.Windows.Media.Imaging;
1415
using System.Xml;
@@ -20,6 +21,24 @@ namespace MediaExtractor
2021
/// </summary>
2122
public class ExtractorItem
2223
{
24+
/// <summary>
25+
/// Default file endings that are previewed as text
26+
/// </summary>
27+
public const string FALLBACK_TEXT_EXTENTIONS = "asc,bas,bat,c,cfg,cmd,cpp,cs,css,csv,h,hex,htm,html,inc,inf,info,ini,java,js,json,kt,ktm,kts,latex,less,lisp,log,lst,lua,markdown,md,me,meta,mf,p,pas,php,pl,pp,ps,ps1,psm1,py,r,rb,readme,reg,rs,rst,sh,sln,sql,sty,tcl,tex,ts,tsx,txt,vb,vba,vbs,yaml,yml";
28+
/// <summary>
29+
/// Default file endings that are previewed as image
30+
/// </summary>
31+
public const string FALLBACK_IMAGE_EXTENTIONS = "jpg,jpeg,png,wmf,emf,gif,bmp,ico,wdp";
32+
/// <summary>
33+
/// Default file endings that are previewed as XML
34+
/// </summary>
35+
public const string FALLBACK_XML_EXTENTIONS = "xml,manifest,rels,xhtml,xaml,svg,pom,dtd,xsd,x3d,collada,cdxml,config,nuspec,graphml";
36+
private static readonly char[] EXT_SPLITTERS = new char[] { ',', ';', ' ', '.', '/', '\\', '|' };
37+
38+
private static List<string> imageExtensions;
39+
private static List<string> textExtensions;
40+
private static List<string> xmlExtensions;
41+
2342
/// <summary>
2443
/// Enum to define the coarse file type of the entry
2544
/// </summary>
@@ -88,7 +107,7 @@ public BitmapImage Image
88107
{
89108
get
90109
{
91-
if (image == null && initialized == false)
110+
if (image == null && !initialized)
92111
{
93112
CreateImage(true);
94113
initialized = true;
@@ -104,7 +123,7 @@ public string GenericText
104123
{
105124
get
106125
{
107-
if (genericText == null && initialized == false)
126+
if (genericText == null && !initialized)
108127
{
109128
if (ItemType == Type.Text)
110129
{
@@ -191,90 +210,19 @@ public ExtractorItem(string fileName, MemoryStream stream, bool createFile, stri
191210
private static Type GetExtensionType(string extension)
192211
{
193212
string ext = extension.ToLower();
194-
switch (ext)
213+
if (textExtensions.Contains(ext))
195214
{
196-
case "asc":
197-
case "bas":
198-
case "bat":
199-
case "c":
200-
case "cmd":
201-
case "config":
202-
case "cpp":
203-
case "cs":
204-
case "css":
205-
case "h":
206-
case "hex":
207-
case "htm":
208-
case "html":
209-
case "inc":
210-
case "ini":
211-
case "java":
212-
case "js":
213-
case "json":
214-
case "kt":
215-
case "ktm":
216-
case "kts":
217-
case "latex":
218-
case "lisp":
219-
case "log":
220-
case "lst":
221-
case "lua":
222-
case "md":
223-
case "me":
224-
case "mf":
225-
case "p":
226-
case "pas":
227-
case "php":
228-
case "pl":
229-
case "pp":
230-
case "ps":
231-
case "py":
232-
case "r":
233-
case "rb":
234-
case "readme":
235-
case "reg":
236-
case "rs":
237-
case "rst":
238-
case "sh":
239-
case "sql":
240-
case "sty":
241-
case "tcl":
242-
case "tex":
243-
case "ts":
244-
case "tsx":
245-
case "txt":
246-
case "vb":
247-
case "vba":
248-
case "vbs":
249-
case "yaml":
250-
case "yml":
251-
return Type.Text;
215+
return Type.Text;
252216
}
253-
switch (ext)
217+
if (xmlExtensions.Contains(ext))
254218
{
255-
case "jpg":
256-
case "jpeg":
257-
case "png":
258-
case "wmf":
259-
case "emf":
260-
case "gif":
261-
case "bmp":
262-
case "ico":
263-
return Type.Image;
219+
return Type.Xml;
264220
}
265-
switch (ext)
221+
if (imageExtensions.Contains(ext))
266222
{
267-
case "xml":
268-
case "rels":
269-
case "xhtml":
270-
case "svg":
271-
case "x3d":
272-
case "collada":
273-
case "graphml":
274-
return Type.Text;
275-
default:
276-
return Type.Other;
223+
return Type.Image;
277224
}
225+
return Type.Other;
278226
}
279227

280228
/// <summary>
@@ -304,7 +252,7 @@ public void CreateText()
304252
public void CreateXml()
305253
{
306254
CreateText();
307-
if (ValidGenericText == false)
255+
if (!ValidGenericText)
308256
{
309257
return;
310258
}
@@ -383,5 +331,45 @@ public void CreateImage(bool retry)
383331
}
384332
}
385333

334+
/// <summary>
335+
/// Method to create valid extensions for the previews
336+
/// </summary>
337+
/// <param name="texts">Raw string of separated text extensions</param>
338+
/// <param name="images">Raw string of separated image extensions</param>
339+
/// <param name="xml">Raw string of separated XML extensions</param>
340+
/// <returns>True if all extensions could be resolved, otherwise false</returns>
341+
public static bool GetExtensions(string texts, string images, string xml)
342+
{
343+
try
344+
{
345+
textExtensions = SplitExtensions(texts);
346+
imageExtensions = SplitExtensions(images);
347+
xmlExtensions = SplitExtensions(xml);
348+
return true;
349+
}
350+
catch
351+
{
352+
textExtensions = SplitExtensions(FALLBACK_TEXT_EXTENTIONS);
353+
imageExtensions = SplitExtensions(FALLBACK_IMAGE_EXTENTIONS);
354+
xmlExtensions = SplitExtensions(FALLBACK_XML_EXTENTIONS);
355+
return false;
356+
}
357+
}
358+
359+
/// <summary>
360+
/// Method to split a raw string of file extensions into a list
361+
/// </summary>
362+
/// <param name="input">input string</param>
363+
/// <returns>List of lowercase, distinct file extensions</returns>
364+
private static List<string> SplitExtensions(string input)
365+
{
366+
if (string.IsNullOrEmpty(input))
367+
{
368+
throw new ArgumentException();
369+
}
370+
string[] split = input.ToLower().Split(EXT_SPLITTERS, StringSplitOptions.RemoveEmptyEntries);
371+
return split.Distinct().ToList();
372+
}
373+
386374
}
387375
}

MediaExtractor/I18N.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public enum Key
4646
DialogErrorTitle,
4747
DialogExplorerError,
4848
DialogHeader,
49+
DialogInvalidExtensions,
4950
DialogLabelCrc,
5051
DialogLabelDate,
5152
DialogLabelExisting,

MediaExtractor/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
</Grid>
107107
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch"/>
108108
<Grid Grid.Column="2" MinWidth="270">
109-
<Border Margin="0,37,0,0" Background="{DynamicResource {x:Static SystemColors.ActiveBorderBrushKey}}">
109+
<Border Margin="0,37,0,0" Background="{DynamicResource {x:Static adonisUi:Brushes.Layer3BackgroundBrush}}">
110110
<Viewbox x:Name="ImageBoxContainer" Margin="10" ClipToBounds="True">
111111
<Image x:Name="ImageBox" />
112112
</Viewbox>

MediaExtractor/MainWindow.xaml.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,10 @@ public MainWindow()
6666
ProductName = versionInfo.ProductName;
6767
// Title = versionInfo.ProductName;
6868
CurrentModel.WindowTitle = versionInfo.ProductName;
69-
//CurrentModel.UseEnglishLocale = true; // TODO: Get from settings
7069
HandleArguments();
7170
}
7271
#endregion
7372

74-
7573
#region publicMethods
7674
/// <summary>
7775
/// Method to change the currently displayed cursor
@@ -96,7 +94,25 @@ public void RestoreSettings()
9694
CurrentModel.KeepFolderStructure = Properties.Settings.Default.DocumentPreserveStructure;
9795
CurrentModel.ShowInExplorer = Properties.Settings.Default.DocumentShowExplorer;
9896
CurrentModel.UseDarkMode = Properties.Settings.Default.AppearanceDarkMode;
97+
if (Properties.Settings.Default.ExtractSaveAll)
98+
{
99+
CurrentModel.SaveAllIsDefault = true; ;
100+
}
101+
else if (Properties.Settings.Default.ExtractSaveSelected)
102+
{
103+
CurrentModel.SaveSelectedIsDefault = true;
104+
}
99105
HandleDarkMode();
106+
string imageExts = Properties.Settings.Default.ImageExtensions;
107+
string textExts = Properties.Settings.Default.TextExtensions;
108+
string xmlExts = Properties.Settings.Default.XmlExtensions;
109+
if (!ExtractorItem.GetExtensions(textExts, imageExts, xmlExts))
110+
{
111+
Properties.Settings.Default.ImageExtensions = ExtractorItem.FALLBACK_IMAGE_EXTENTIONS;
112+
Properties.Settings.Default.TextExtensions = ExtractorItem.FALLBACK_TEXT_EXTENTIONS;
113+
Properties.Settings.Default.XmlExtensions = ExtractorItem.FALLBACK_XML_EXTENTIONS;
114+
MessageBox.Show(I18n.T(I18n.Key.DialogInvalidExtensions), I18n.T(I18n.Key.DialogErrorTitle), MessageBoxButton.OK, MessageBoxImage.Error);
115+
}
100116
}
101117

102118
/// <summary>
@@ -140,7 +156,7 @@ private void HandleArguments()
140156
if (args.Length > 1)
141157
{
142158
string fileName = args[1];
143-
if (File.Exists(fileName) == false) { return; }
159+
if (!File.Exists(fileName)) { return; }
144160
else
145161
{
146162
CurrentModel.FileName = args[1];
@@ -197,7 +213,6 @@ private void HandleDarkMode()
197213
if (CurrentModel.UseDarkMode)
198214
{
199215
AdonisUI.ResourceLocator.SetColorScheme(Application.Current.Resources, ResourceLocator.DarkColorScheme);
200-
201216
}
202217
else
203218
{
@@ -226,6 +241,8 @@ private void StoreSettings()
226241
Properties.Settings.Default.DocumentPreserveStructure = CurrentModel.KeepFolderStructure;
227242
Properties.Settings.Default.DocumentShowExplorer = CurrentModel.ShowInExplorer;
228243
Properties.Settings.Default.AppearanceDarkMode = CurrentModel.UseDarkMode;
244+
Properties.Settings.Default.ExtractSaveAll = CurrentModel.SaveAllIsDefault;
245+
Properties.Settings.Default.ExtractSaveSelected = CurrentModel.SaveSelectedIsDefault;
229246
Properties.Settings.Default.Locale = CurrentLocale;
230247
Properties.Settings.Default.Save();
231248
}
@@ -551,10 +568,9 @@ private void WebsiteMenuItem_Click(object sender, RoutedEventArgs e)
551568
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
552569
private void LicenseMenuItem_Click(object sender, RoutedEventArgs e)
553570
{
554-
if (Utils.ShowInExplorer("license.txt") == false)
571+
if (!Utils.ShowInExplorer("license.txt"))
555572
{
556-
MessageBox.Show(I18n.R(I18n.Key.DialogMissingLicense, "license.txt"), I18n.T(I18n.Key.DialogMissingLicenseTitle),
557-
MessageBoxButton.OK, MessageBoxImage.Warning);
573+
MessageBox.Show(I18n.R(I18n.Key.DialogMissingLicense, "license.txt"), I18n.T(I18n.Key.DialogMissingLicenseTitle), MessageBoxButton.OK, MessageBoxImage.Warning);
558574
}
559575
}
560576

@@ -565,7 +581,7 @@ private void LicenseMenuItem_Click(object sender, RoutedEventArgs e)
565581
/// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
566582
private void ChangeLogMenuItem_Click(object sender, RoutedEventArgs e)
567583
{
568-
if (Utils.ShowInExplorer("changelog.txt") == false)
584+
if (!Utils.ShowInExplorer("changelog.txt"))
569585
{
570586
MessageBox.Show(I18n.R(I18n.Key.DialogMissingChangelog, "changelog.txt"), I18n.T(I18n.Key.DialogMissingChangelogTitle),
571587
MessageBoxButton.OK, MessageBoxImage.Warning);

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.4.1.0")]
26-
[assembly: AssemblyFileVersion("1.4.1.0")]
25+
[assembly: AssemblyVersion("1.5.0.0")]
26+
[assembly: AssemblyFileVersion("1.5.0.0")]

MediaExtractor/Properties/Resources.Designer.cs

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MediaExtractor/Properties/Resources.de-DE.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
<value>Ordnerstruktur beim Entpacken erhalten</value>
146146
</data>
147147
<data name="MenuDocumentOpenExplorer" xml:space="preserve">
148-
<value>Nach dem Entpacken in Explorer zeiegen</value>
148+
<value>Nach dem Entpacken in Explorer zeigen</value>
149149
</data>
150150
<data name="MenuAppearance" xml:space="preserve">
151151
<value>Ansicht</value>
@@ -417,4 +417,7 @@
417417
<data name="TextErrorInvalidText" xml:space="preserve">
418418
<value>Textvorschau konnte nicht erstellt werden</value>
419419
</data>
420+
<data name="DialogInvalidExtensions" xml:space="preserve">
421+
<value>Beim Ermitteln der Dateiendungen für die Vorschau ist ein Fehler aufgetreten. Die Standardwerte werden wiederhergestellt.</value>
422+
</data>
420423
</root>

0 commit comments

Comments
 (0)