Skip to content

Commit

Permalink
Added versioning.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlebansais committed Aug 18, 2019
1 parent 44512a9 commit 0d1915e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
54 changes: 52 additions & 2 deletions PgBrewer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Windows;
Expand All @@ -19,6 +20,7 @@ public partial class MainWindow : Window, INotifyPropertyChanged
#region Constants
private static readonly string AssociationSettingName = "Association";
private static readonly string GuiSettingName = "GUI";
private static readonly string VersionProlog = "Exported from PgBrewing.exe version ";
#endregion

#region Init
Expand Down Expand Up @@ -575,6 +577,8 @@ private void OnExport(string FileName)

private void OnExport(StreamWriter writer)
{
ExportVersionNumber(writer);

ExportAssociations(writer);

BasicLager.Export(writer);
Expand All @@ -595,6 +599,12 @@ private void OnExport(StreamWriter writer)
Bourbon.Export(writer);
}

private void ExportVersionNumber(StreamWriter writer)
{
string Version = GetVersion();
writer.WriteLine($"{VersionProlog}{Version}");
}

private void ExportAssociations(StreamWriter writer)
{
writer.WriteLine("Associations");
Expand Down Expand Up @@ -644,8 +654,6 @@ private void OnImport(string FileName)
MessageBox.Show("The imported file contains the same data as the software.\r\n\r\nNo change made.", "Import", MessageBoxButton.OK, MessageBoxImage.Warning);
else
MessageBox.Show("File content imported.", "Import", MessageBoxButton.OK, MessageBoxImage.Information);
else
MessageBox.Show("Invalid format, not all of the file content was imported.", "Import", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
Expand All @@ -656,6 +664,40 @@ private void OnImport(string FileName)
}

private bool OnImport(StreamReader reader, ref int changeCount)
{
if (!ImportVersionNumber(reader))
return false;

if (OnImportConfirmed(reader, ref changeCount))
return true;
else
{
MessageBox.Show("Invalid format, not all of the file content was imported.", "Import", MessageBoxButton.OK, MessageBoxImage.Error);
return false;
}
}

private bool ImportVersionNumber(StreamReader reader)
{
string Version = GetVersion();

string Line = reader.ReadLine();
if (!Line.StartsWith(VersionProlog))
return false;

Line = Line.Substring(VersionProlog.Length);

if (Line != Version)
{
MessageBoxResult Answer = MessageBox.Show($"This file was exported from version {Line}. The current version is {Version} and is probably not compatible. Continue?", "Import", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (Answer != MessageBoxResult.Yes)
return false;
}

return true;
}

private bool OnImportConfirmed(StreamReader reader, ref int changeCount)
{
if (!ImportAssociations(reader, ref changeCount))
return false;
Expand Down Expand Up @@ -770,6 +812,14 @@ private bool ImportAssociations(StreamReader reader, ref int changeCount)
return true;
}

private string GetVersion()
{
Assembly CurrentAssembly = Assembly.GetExecutingAssembly();
FileVersionInfo VersionInfo = FileVersionInfo.GetVersionInfo(CurrentAssembly.Location);

return VersionInfo.FileVersion;
}

public void OnGotFocus(ComboBox sender)
{
LastFocusedCombo = sender;
Expand Down
4 changes: 2 additions & 2 deletions PgBrewer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.1")]
[assembly: AssemblyFileVersion("1.0.0.1")]
[assembly: AssemblyVersion("1.0.0.6")]
[assembly: AssemblyFileVersion("1.0.0.6")]

0 comments on commit 0d1915e

Please sign in to comment.