Skip to content

Commit

Permalink
Some basic modernizations
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsuo13 committed Feb 11, 2024
1 parent 30124ab commit 6bfe288
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 32 deletions.
13 changes: 6 additions & 7 deletions ImageViewer/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using ExifLib;
using System;
using System.IO;
using System.Windows.Forms;
using ExifLib;

namespace ImageViewer
{
Expand Down Expand Up @@ -36,20 +36,19 @@ private void ShowImageInfo(string fileName)
catch (Exception e)
{
// Probably no tags to display.
listBox1.Items.Add(String.Format("Error reading file: {0}", e.Message));
listBox1.Items.Add(string.Format("Error reading file: {0}", e.Message));
return;
}

foreach (ExifTags tag in Enum.GetValues(typeof(ExifTags)))
{
try
{
string exifValue;
reader.GetTagValue<string>(tag, out exifValue);
reader.GetTagValue<string>(tag, out string exifValue);

if (!String.IsNullOrEmpty(exifValue))
if (!string.IsNullOrEmpty(exifValue))
{
string item = String.Format("{0}: {1}",
var item = string.Format("{0}: {1}",
Enum.GetName(typeof(ExifTags), tag), exifValue);
listBox1.Items.Add(item);
}
Expand Down
2 changes: 1 addition & 1 deletion Slideshow/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void App_Startup(object sender, StartupEventArgs e)
}
else
{
dragNdropArg = "";
dragNdropArg = string.Empty;
}
}

Expand Down
37 changes: 19 additions & 18 deletions Slideshow/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ public partial class MainWindow : Window
/// <summary>
/// Number of seconds to increment/decrement image duration at a time.
/// </summary>
private int imageDurationOffset = 4;
private readonly int imageDurationOffset = 4;

/// <summary>
/// Collection of images that were found and their properties.
/// </summary>
private List<Media> images = new List<Media>();
private readonly List<Media> images = new List<Media>();

private int currentImageIndex = 0;
private DispatcherTimer imageTimer = new DispatcherTimer();
private readonly DispatcherTimer imageTimer = new DispatcherTimer();

public MainWindow()
{
InitializeComponent();

this.Cursor = Cursors.None;
this.KeyDown += new KeyEventHandler(MainWindow_KeyDown);
Cursor = Cursors.None;
KeyDown += new KeyEventHandler(MainWindow_KeyDown);

LoadImages();

Expand All @@ -60,8 +60,10 @@ private void Toast(string notification)
AppInfo.Content = notification;
AppInfo.Visibility = Visibility.Visible;

DispatcherTimer toastTimer = new DispatcherTimer();
toastTimer.Interval = new TimeSpan(0, 0, 2);
var toastTimer = new DispatcherTimer
{
Interval = new TimeSpan(0, 0, 2)
};
toastTimer.Tick += (EventHandler)delegate(object snd, EventArgs ea)
{
AppInfo.Visibility = Visibility.Collapsed;
Expand All @@ -83,7 +85,7 @@ void MainWindow_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
this.Close();
Close();
return;
}

Expand All @@ -96,7 +98,6 @@ void MainWindow_KeyDown(object sender, KeyEventArgs e)
{
// Increment image duration.
case Key.Add:
// Break intentionally omitted.
case Key.OemPlus:
imageDurationSeconds += imageDurationOffset;
imageTimer.Interval = new TimeSpan(0, 0, imageDurationSeconds);
Expand All @@ -105,7 +106,6 @@ void MainWindow_KeyDown(object sender, KeyEventArgs e)

// Decrement image duration.
case Key.Subtract:
// Break intentionally omitted.
case Key.OemMinus:
if (imageDurationSeconds <= 1)
{
Expand Down Expand Up @@ -147,11 +147,11 @@ private void DisplayImage(bool advanceImageIndex = true)
using (FileStream imageStream = new FileStream(images[currentImageIndex].File.FullName, FileMode.Open,
FileAccess.Read, FileShare.ReadWrite))
{
MemoryStream memoryStream = new MemoryStream();
var memoryStream = new MemoryStream();
memoryStream.SetLength(imageStream.Length);
imageStream.Read(memoryStream.GetBuffer(), 0, (int)imageStream.Length);

BitmapImage bitmapImage = new BitmapImage();
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.StreamSource = memoryStream;
bitmapImage.EndInit();
Expand All @@ -174,7 +174,7 @@ private void DisplayImage(bool advanceImageIndex = true)

private void DisplayImageInfo()
{
this.ImageInfo.Content = images[currentImageIndex].InfoText();
ImageInfo.Content = images[currentImageIndex].InfoText();
}

private void ChangeImageIndex(int offset)
Expand Down Expand Up @@ -202,7 +202,7 @@ private void timer_Tick(object sender, EventArgs e)

private void ReadExifInfo(FileStream imageStream)
{
if (!String.IsNullOrEmpty(images[currentImageIndex].InfoText()))
if (!string.IsNullOrEmpty(images[currentImageIndex].InfoText()))
{
return;
}
Expand All @@ -214,6 +214,7 @@ private void ReadExifInfo(FileStream imageStream)
}
catch (Exception)
{
// No info will be displayed.
}
}

Expand All @@ -224,9 +225,9 @@ private void LoadImages()
{
string[] validExtensions = new string[] { ".jpg", ".jpeg" };
DirectoryInfo directory;
if (Slideshow.App.dragNdropArg.Length > 0)
if (App.dragNdropArg.Length > 0)
{
directory = new DirectoryInfo(GetSelectedDirectory(Slideshow.App.dragNdropArg));
directory = new DirectoryInfo(GetSelectedDirectory(App.dragNdropArg));
}
else
{
Expand All @@ -247,14 +248,14 @@ where validExtensions.Any(f.Extension.ToLower().Contains)
private string GetAssemblyDirectory()
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
var uri = new UriBuilder(codeBase);
string assemblyPath = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(assemblyPath);
}

private string GetSelectedDirectory(string arg)
{
UriBuilder uri = new UriBuilder(arg);
var uri = new UriBuilder(arg);
string argPath = Uri.UnescapeDataString(uri.Path);
if (Directory.Exists(argPath))
{
Expand Down
5 changes: 2 additions & 3 deletions Slideshow/Media.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ExifLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -30,8 +29,8 @@ public Media()
/// <returns></returns>
public string InfoText()
{
return String.Join("\n", Info.Select(x => x.TagValue)
.Where(x => !String.IsNullOrEmpty(x))
return string.Join("\n", Info.Select(x => x.TagValue)
.Where(x => !string.IsNullOrEmpty(x))
.ToArray());
}
}
Expand Down
3 changes: 1 addition & 2 deletions Slideshow/MediaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public MediaInfo(ExifTags tag)

public void SetValue(ExifReader reader)
{
string tmp;
reader.GetTagValue<string>(Tag, out tmp);
reader.GetTagValue(Tag, out string tmp);
TagValue = tmp;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Slideshow/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Andrei Nicholson")]
[assembly: AssemblyProduct("Slideshow")]
[assembly: AssemblyCopyright("Copyright © Andrei Nicholson 2014")]
[assembly: AssemblyCopyright("Copyright © 2014 Andrei Nicholson")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down

0 comments on commit 6bfe288

Please # to comment.