diff --git a/Package.nuspec b/Package.nuspec
index e2dbbcb..02559de 100644
--- a/Package.nuspec
+++ b/Package.nuspec
@@ -11,16 +11,16 @@
https://codedead.com/Software/codedead.png
true
- This library can be used to check for application updates. It is designed for WPF and Windows Forms applications. In order to use it, you require an XML or JSON file on a remote or local server that represents the Update class.
+ This library can be used to check for application updates. It is designed for .NET Standard 2.0 applications. In order to use it, you require an XML or JSON file on a remote or local server that represents the Update class.
- Added support for asynchronously checking for updates
+ Library is now .NET Standard 2.0 compliant and added support for asynchronously checking for updates
Copyright © 2019 CodeDead
CodeDead UpdateManager Update Updater updates updating downloader downloading
-
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 20bfb3b..28e4379 100644
--- a/README.md
+++ b/README.md
@@ -1,82 +1,138 @@
-# UpdateManager
-UpdateManager was created by DeadLine. This library was developed free of charge.
+
+
+
+# UpdateManager [](https://www.nuget.org/packages/CodeDead.UpdateManager/) [](https://codedead.com/?page_id=302)
This library can be used to check for application updates. It is designed for WPF and Windows Forms applications.
In order to use it, you require an XML or JSON file on a remote or local server that represents the Update class.
-## Dependencies
-* [.NET Framework 4.8](https://dotnet.microsoft.com/download/dotnet-framework/net48)
+### Dependencies
+* .NET Standard 2.0
+
+## Sample projects
+Sample projects can be found here:
+https://github.com/CodeDead/UpdateManager/tree/master/UpdateManager.Sample
+https://github.com/CodeDead/UpdateManager/tree/master/UpdateManager.Sample.WPF
## Usage
UpdateManager is available as a [NuGet package](https://www.nuget.org/packages/CodeDead.UpdateManager/). You can find it here:
https://www.nuget.org/packages/CodeDead.UpdateManager/
-Sample projects can be found here:
-https://github.com/CodeDead/UpdateManager/tree/master/UpdateManager.Sample
-https://github.com/CodeDead/UpdateManager/tree/master/UpdateManager.Sample.WPF
+You can install the package using your package manager:
+```NuGet
+Install-Package CodeDead.UpdateManager
+```
+Command-line:
+```CLI
+dotnet add package CodeDead.UpdateManager
+```
-Create a new *UpdateManager* object like this:
+After the package has been added to your project, you can create a new *UpdateManager* object using the default constructor:
```C#
-// Import statement
-using CodeDead.UpdateManager.Classes;
-
// Initialize a new UpdateManager object
UpdateManager updateManager = new UpdateManager();
```
-You can check for updates like this:
+It is important to set the platform of the current application. The *CurrentPlatform* property is used to determine which *Update* object is applicable to the running application:
+
```C#
-try
-{
- // Retrieve the latest Update object from the remote location
- Update update = updateManager.GetLatestVersion();
-}
-catch (Exception ex)
-{
- MessageBox.Show(ex.Message, "Application title", MessageBoxButton.OK, MessageBoxImage.Error);
-}
+// Set the CurrentPlatform property
+updateManager.CurrentPlatform = "win32";
```
-## Update types
-Updates can be stored and parsed in two different formats: *JSON* or *XML*. By default, the *DataType* property will be set to *Json*. You can change the *DataType* property by setting the appropriate property on the *UpdateManager* object:
+
+In order to retrieve the latest version, you will also need to specify a remote location where the *PlatformUpdates* object is stored:
+```C#
+// Set the UpdateUrl property
+updateManager.UpdateUrl = "https://codedead.com/Software/UpdateManager/example.json";
+```
+
+After the *CurrentPlatform* and *UpdateUrl* properties have been set, you can check for updates by calling the *GetLatestVersion()* method of an *UpdateManager* object. An *Update* object will be returned, that you can then use to check for updates:
+```C#
+// Retrieve the latest Update object from the remote location
+Update update = updateManager.GetLatestVersion();
+// Check if an update is available
+bool updateAvailable = update.UpdateAvailable(Assembly.GetExecutingAssembly().GetName().Version);
+```
+
+## PlatformUpdates
+*Update* objects can be retrieved for multiple platforms. The *PlatformUpdates* object is the root object that should be retrieved from a remote location.
+
+A *PlatformUpdates* object can be stored and parsed in two different formats: *JSON* or *XML*. By default, the *DataType* property will be set to *Json*. You can change the *DataType* property by setting the appropriate property on the *UpdateManager* object:
```C#
-// Initialize a new UpdateManager object
-UpdateManager updateManager = new UpdateManager();
// Set the data type of the remote Update object representation
updateManager.DataType = DataType.Json;
```
```C#
-// Initialize a new UpdateManager object
-UpdateManager updateManager = new UpdateManager();
// Set the data type of the remote Update object representation
updateManager.DataType = DataType.Xml;
```
-### JSON Update example
+### *PlatformUpdates* JSON example
```JSON
{
- "MajorVersion": 1,
- "MinorVersion": 0,
- "BuildVersion": 0,
- "RevisionVersion": 0,
- "UpdateUrl": "https://codedead.com/update.exe",
- "InfoUrl": "https://codedead.com",
- "UpdateInfo": "A new version is now available. Please click the download button to download version 1.0.0.0"
+ "PlatformUpdateList": [
+ {
+ "PlatformName": "win32",
+ "Update": {
+ "MajorVersion": 2,
+ "MinorVersion": 0,
+ "BuildVersion": 0,
+ "RevisionVersion": 0,
+ "UpdateUrl": "https://codedead.com/example.exe",
+ "InfoUrl": "https://codedead.com",
+ "UpdateInfo": "A new version is now available.\nPlease click the download button to download version 2.0.0.0"
+ }
+ },
+ {
+ "PlatformName": "linux",
+ "Update": {
+ "MajorVersion": 2,
+ "MinorVersion": 0,
+ "BuildVersion": 0,
+ "RevisionVersion": 0,
+ "UpdateUrl": "https://codedead.com/example.exe",
+ "InfoUrl": "https://codedead.com",
+ "UpdateInfo": "A new version is now available.\nPlease click the download button to download version 2.0.0.0"
+ }
+ }
+ ]
}
```
-### XML Update example
+### *PlatformUpdates* XML example
```XML
-
- 1
- 0
- 0
- 0
- https://example.com/update.exe
- https://codedead.com/
- A new version is now available. Please click the download button to download version 1.0.0.0
-
+
+
+
+ win32
+
+ 2
+ 0
+ 0
+ 0
+ https://codedead.com/Software/PK%20Finder/PK_setup.exe
+ https://codedead.com
+ A new version is now available. Please click the download button to download version 2.0.0.0
+
+
+
+ linux
+
+ 2
+ 0
+ 0
+ 0
+ https://codedead.com/Software/PK%20Finder/PK_setup.exe
+ https://codedead.com
+ A new version is now available. Please click the download button to download version 2.0.0.0
+
+
+
+
```
# About
diff --git a/UpdateManager.Sample.WPF/App.xaml b/UpdateManager.Sample.WPF/App.xaml
index 0c7be3d..1733365 100644
--- a/UpdateManager.Sample.WPF/App.xaml
+++ b/UpdateManager.Sample.WPF/App.xaml
@@ -1,7 +1,7 @@
+ StartupUri="Windows/MainWindow.xaml">
diff --git a/UpdateManager.Sample.WPF/UpdateManager.Sample.WPF.csproj b/UpdateManager.Sample.WPF/UpdateManager.Sample.WPF.csproj
index 118f208..e2e9b0b 100644
--- a/UpdateManager.Sample.WPF/UpdateManager.Sample.WPF.csproj
+++ b/UpdateManager.Sample.WPF/UpdateManager.Sample.WPF.csproj
@@ -35,6 +35,9 @@
4
+
+ ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
+
@@ -50,7 +53,7 @@
MSBuild:Compile
Designer
-
+
MSBuild:Compile
Designer
@@ -58,7 +61,7 @@
App.xaml
Code
-
+
MainWindow.xaml
Code
@@ -81,6 +84,7 @@
ResXFileCodeGenerator
Resources.Designer.cs
+
SettingsSingleFileGenerator
Settings.Designer.cs
@@ -91,9 +95,14 @@
- {4e804ead-446a-47cc-b231-0a6255b867a3}
+ {2a14f99d-81a1-432d-80da-6471eda85aaa}
UpdateManager
+
+ {60ea74ad-ae82-4259-ba77-780c4bf9527d}
+ UpdateManager.WPF
+
+
\ No newline at end of file
diff --git a/UpdateManager.Sample.WPF/MainWindow.xaml b/UpdateManager.Sample.WPF/Windows/MainWindow.xaml
similarity index 75%
rename from UpdateManager.Sample.WPF/MainWindow.xaml
rename to UpdateManager.Sample.WPF/Windows/MainWindow.xaml
index ef7827f..16bdda5 100644
--- a/UpdateManager.Sample.WPF/MainWindow.xaml
+++ b/UpdateManager.Sample.WPF/Windows/MainWindow.xaml
@@ -1,10 +1,10 @@
-
+ Title="UpdateManager WPF Sample" Height="450" Width="800">
diff --git a/UpdateManager.Sample.WPF/MainWindow.xaml.cs b/UpdateManager.Sample.WPF/Windows/MainWindow.xaml.cs
similarity index 55%
rename from UpdateManager.Sample.WPF/MainWindow.xaml.cs
rename to UpdateManager.Sample.WPF/Windows/MainWindow.xaml.cs
index f47443e..802934f 100644
--- a/UpdateManager.Sample.WPF/MainWindow.xaml.cs
+++ b/UpdateManager.Sample.WPF/Windows/MainWindow.xaml.cs
@@ -1,13 +1,17 @@
-using System.Reflection;
+using System;
+using System.Reflection;
using System.Windows;
-using CodeDead.UpdateManager.Classes;
+using CodeDead.UpdateManager;
+using CodeDead.UpdateManager.Objects;
+using CodeDead.UpdateManager.WPF;
+using CodeDead.UpdateManager.WPF.Objects;
-namespace UpdateManager.Sample.WPF
+namespace UpdateManager.Sample.WPF.Windows
{
///
/// Interaction logic for MainWindow.xaml
///
- public partial class MainWindow : Window
+ public partial class MainWindow
{
///
/// Initialize a new MainWindow
@@ -25,7 +29,7 @@ public MainWindow()
private async void UpdateButton_Click(object sender, RoutedEventArgs e)
{
// Initialize a new UpdateManager object
- CodeDead.UpdateManager.Classes.UpdateManager updateManager = new CodeDead.UpdateManager.Classes.UpdateManager();
+ CodeDead.UpdateManager.UpdateManager updateManager = new CodeDead.UpdateManager.UpdateManager();
// Initialize and set the StringVariables that can be used by the dialog functionality
StringVariables stringVariables = new StringVariables
@@ -33,28 +37,32 @@ private async void UpdateButton_Click(object sender, RoutedEventArgs e)
CancelButtonText = "Cancel",
DownloadButtonText = "Download",
InformationButtonText = "Information",
- NoNewVersionText = "You are running the latest version!",
TitleText = "UpdateManager Sample",
UpdateNowText = "Would you like to update to the latest version now?"
};
- // Automatically get the current application's version by utilizing
- updateManager.ApplicationVersion = Assembly.GetExecutingAssembly().GetName().Version;
-
// Set the data type of the remote Update object representation
updateManager.DataType = DataType.Json;
+ // Set the current platform
+ updateManager.CurrentPlatform = "win32";
// Set the remote address where the Update object representation is located
- updateManager.UpdateUrl = "https://codedead.com/Software/PK%20Finder/update.json";
- // Set that a message should be displayed if no updates are available
- updateManager.ShowNoUpdates = true;
- // Set the StringVariables object
- updateManager.StringVariables = stringVariables;
+ updateManager.UpdateUrl = "https://codedead.com/Software/UpdateManager/example.json";
- // Retrieve the latest Update object from the remote location asynchronously
- Update update = await updateManager.GetLatestVersionAsync();
+ try
+ {
+ // Retrieve the latest Update object from the remote location asynchronously
+ Update update = await updateManager.GetLatestVersionAsync();
- // Display an update dialog, if applicable
- updateManager.DisplayUpdateDialog(update);
+ // Display an update dialog, if applicable
+ if (update.UpdateAvailable(Assembly.GetExecutingAssembly().GetName().Version))
+ {
+ new UpdateDialogManager(stringVariables).DisplayUpdateDialog(update);
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "UpdateManager WPF Sample", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
}
}
}
diff --git a/UpdateManager.Sample.WPF/packages.config b/UpdateManager.Sample.WPF/packages.config
new file mode 100644
index 0000000..281c145
--- /dev/null
+++ b/UpdateManager.Sample.WPF/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/UpdateManager.Sample/Program.cs b/UpdateManager.Sample/Program.cs
index c2231c3..d95c3e3 100644
--- a/UpdateManager.Sample/Program.cs
+++ b/UpdateManager.Sample/Program.cs
@@ -1,5 +1,6 @@
using System;
-using CodeDead.UpdateManager.Classes;
+using CodeDead.UpdateManager;
+using CodeDead.UpdateManager.Objects;
namespace UpdateManager.Sample
{
@@ -8,42 +9,31 @@ namespace UpdateManager.Sample
///
internal class Program
{
- [STAThread]
private static void Main()
{
// Initialize a new UpdateManager object
- CodeDead.UpdateManager.Classes.UpdateManager updateManager = new CodeDead.UpdateManager.Classes.UpdateManager();
-
- // Initialize and set the StringVariables that can be used by the dialog functionality
- StringVariables stringVariables = new StringVariables
- {
- CancelButtonText = "Cancel",
- DownloadButtonText = "Download",
- InformationButtonText = "Information",
- NoNewVersionText = "You are running the latest version!",
- TitleText = "UpdateManager Sample",
- UpdateNowText = "Would you like to update to the latest version now?"
- };
-
- // Set the version of the current application
- updateManager.ApplicationVersion = new Version(1, 0, 0, 0);
- // Alternatively, you can automatically get the current application's version by utilizing:
- // updateManager.ApplicationVersion = Assembly.GetExecutingAssembly().GetName().Version;
-
- // Set the data type of the remote Update object representation
+ CodeDead.UpdateManager.UpdateManager updateManager = new CodeDead.UpdateManager.UpdateManager();
+
+ // Set the platform of the current application
+ updateManager.CurrentPlatform = "win32";
+ // Set the data type of the remote Update object (optional for JSON, since this is the default data type)
updateManager.DataType = DataType.Json;
// Set the remote address where the Update object representation is located
- updateManager.UpdateUrl = "https://codedead.com/Software/PK%20Finder/update.json";
- // Set that a message should be displayed if no updates are available
- updateManager.ShowNoUpdates = true;
- // Set the StringVariables object
- updateManager.StringVariables = stringVariables;
+ updateManager.UpdateUrl = "https://codedead.com/Software/UpdateManager/example.json";
- // Retrieve the latest Update object from the remote location
- Update update = updateManager.GetLatestVersion();
-
- // Display an update dialog, if applicable
- updateManager.DisplayUpdateDialog(update);
+ try
+ {
+ // Retrieve the latest Update object from the remote location
+ Update update = updateManager.GetLatestVersion();
+ // Alternatively, you can automatically get the current application's version by utilizing Assembly.GetExecutingAssembly().GetName().Version;
+ Console.WriteLine("Update available: " + update.UpdateAvailable(new Version(1, 0, 0, 0)));
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex.Message);
+ }
+
+ Console.ReadLine();
}
}
}
diff --git a/UpdateManager.Sample/UpdateManager.Sample.csproj b/UpdateManager.Sample/UpdateManager.Sample.csproj
index 4b8e7c6..3995b02 100644
--- a/UpdateManager.Sample/UpdateManager.Sample.csproj
+++ b/UpdateManager.Sample/UpdateManager.Sample.csproj
@@ -33,8 +33,12 @@
4
+
+ ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
+
+
@@ -42,10 +46,11 @@
+
- {4e804ead-446a-47cc-b231-0a6255b867a3}
+ {2a14f99d-81a1-432d-80da-6471eda85aaa}
UpdateManager
diff --git a/UpdateManager.Sample/packages.config b/UpdateManager.Sample/packages.config
new file mode 100644
index 0000000..281c145
--- /dev/null
+++ b/UpdateManager.Sample/packages.config
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/UpdateManager.WPF/App.config b/UpdateManager.WPF/App.config
new file mode 100644
index 0000000..35e8549
--- /dev/null
+++ b/UpdateManager.WPF/App.config
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/UpdateManager/Classes/StringVariables.cs b/UpdateManager.WPF/Objects/StringVariables.cs
similarity index 83%
rename from UpdateManager/Classes/StringVariables.cs
rename to UpdateManager.WPF/Objects/StringVariables.cs
index c7cd780..6525ceb 100644
--- a/UpdateManager/Classes/StringVariables.cs
+++ b/UpdateManager.WPF/Objects/StringVariables.cs
@@ -1,4 +1,4 @@
-namespace CodeDead.UpdateManager.Classes
+namespace CodeDead.UpdateManager.WPF.Objects
{
///
/// Class containing all available strings that can be displayed to the user
@@ -27,11 +27,6 @@ public sealed class StringVariables
///
public string DownloadButtonText { get; set; }
- ///
- /// The text that should appear in the MessageBox when the user is running the latest version (or newer)
- ///
- public string NoNewVersionText { get; set; }
-
///
/// The text that should be displayed to the user to ask whether or not the update should be executed or not after the download has completed
///
@@ -48,7 +43,6 @@ public StringVariables()
InformationButtonText = "";
CancelButtonText = "";
DownloadButtonText = "";
- NoNewVersionText = "";
UpdateNowText = "";
}
}
diff --git a/UpdateManager/Properties/AssemblyInfo.cs b/UpdateManager.WPF/Properties/AssemblyInfo.cs
similarity index 79%
rename from UpdateManager/Properties/AssemblyInfo.cs
rename to UpdateManager.WPF/Properties/AssemblyInfo.cs
index 0044181..099a22a 100644
--- a/UpdateManager/Properties/AssemblyInfo.cs
+++ b/UpdateManager.WPF/Properties/AssemblyInfo.cs
@@ -4,11 +4,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
-[assembly: AssemblyTitle("UpdateManager")]
-[assembly: AssemblyDescription("UpdateManager")]
+[assembly: AssemblyTitle("UpdateManager.WPF")]
+[assembly: AssemblyDescription("UpdateManager.WPF")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("CodeDead")]
-[assembly: AssemblyProduct("UpdateManager")]
+[assembly: AssemblyProduct("UpdateManager.WPF")]
[assembly: AssemblyCopyright("Copyright © 2020 CodeDead")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -19,7 +19,7 @@
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("4e804ead-446a-47cc-b231-0a6255b867a3")]
+[assembly: Guid("60ea74ad-ae82-4259-ba77-780c4bf9527d")]
// Version information for an assembly consists of the following four values:
//
@@ -31,5 +31,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.6.0.0")]
-[assembly: AssemblyFileVersion("1.6.0.0")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/UpdateManager.WPF/UpdateDialogManager.cs b/UpdateManager.WPF/UpdateDialogManager.cs
new file mode 100644
index 0000000..8341335
--- /dev/null
+++ b/UpdateManager.WPF/UpdateDialogManager.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Windows;
+using CodeDead.UpdateManager.Objects;
+using CodeDead.UpdateManager.WPF.Objects;
+using CodeDead.UpdateManager.WPF.Windows;
+
+namespace CodeDead.UpdateManager.WPF
+{
+ ///
+ /// Class that contains logic to display an update dialog
+ ///
+ public sealed class UpdateDialogManager
+ {
+ #region Variables
+
+ private StringVariables _stringVariables;
+
+ #endregion
+
+ ///
+ /// Initialize a new UpdateDialogManager
+ ///
+ public UpdateDialogManager()
+ {
+ StringVariables = new StringVariables();
+ }
+
+ ///
+ /// Initialize a new UpdateDialogManager
+ ///
+ /// The StringVariables object that can be used to display text in the update dialog
+ public UpdateDialogManager(StringVariables stringVariables)
+ {
+ StringVariables = stringVariables;
+ }
+
+ #region Properties
+
+ ///
+ /// Gets or sets the StringVariables
+ ///
+ public StringVariables StringVariables
+ {
+ get => _stringVariables;
+ set => _stringVariables = value ?? throw new ArgumentNullException(nameof(value));
+ }
+
+ ///
+ /// Gets or sets whether the information button should be displayed
+ ///
+ public bool ShowInformationButton { get; set; } = true;
+
+ ///
+ /// Gets or sets whether the cancel button should be displayed
+ ///
+ public bool ShowCancelButton { get; set; } = true;
+
+ ///
+ /// Gets or sets whether the download button should be displayed
+ ///
+ public bool ShowDownloadButton { get; set; } = true;
+
+ ///
+ /// Gets or sets whether the built-in downloading functionality should be used
+ ///
+ public bool UseDownloader { get; set; } = true;
+
+ #endregion
+
+ ///
+ /// Display an update dialog, if applicable
+ ///
+ /// The Update that contains the latest information regarding the version
+ public void DisplayUpdateDialog(Update applicationUpdate)
+ {
+ if (applicationUpdate == null) throw new ArgumentNullException(nameof(applicationUpdate));
+
+ UpdateWindow window = new UpdateWindow
+ {
+ Title = StringVariables.TitleText,
+ InformationTextBlockContent = applicationUpdate.UpdateInfo,
+ InformationButtonContent = StringVariables.InformationButtonText,
+ CancelButtonContent = StringVariables.CancelButtonText,
+ DownloadButtonContent = StringVariables.DownloadButtonText,
+ DownloadUrl = applicationUpdate.UpdateUrl,
+ InformationUrl = applicationUpdate.InfoUrl,
+ UpdateNowText = StringVariables.UpdateNowText,
+ UseDownloader = UseDownloader
+ };
+
+ if (!ShowCancelButton && !ShowDownloadButton && !ShowInformationButton)
+ {
+ window.GrdButtons.Visibility = Visibility.Collapsed;
+ }
+
+ if (!ShowCancelButton)
+ {
+ window.BtnCancel.Visibility = Visibility.Collapsed;
+ }
+
+ if (!ShowDownloadButton)
+ {
+ window.BtnDownload.Visibility = Visibility.Collapsed;
+ }
+
+ if (!ShowInformationButton)
+ {
+ window.BtnInformation.Visibility = Visibility.Collapsed;
+ }
+
+ window.ShowDialog();
+ }
+ }
+}
diff --git a/UpdateManager.WPF/UpdateManager.WPF.csproj b/UpdateManager.WPF/UpdateManager.WPF.csproj
new file mode 100644
index 0000000..88fe89c
--- /dev/null
+++ b/UpdateManager.WPF/UpdateManager.WPF.csproj
@@ -0,0 +1,71 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {60EA74AD-AE82-4259-BA77-780C4BF9527D}
+ Library
+ CodeDead.UpdateManager.WPF
+ CodeDead.UpdateManager.WPF
+ v4.8
+ 512
+ true
+ true
+
+
+ AnyCPU
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ AnyCPU
+ none
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ UpdateWindow.xaml
+
+
+
+
+
+
+
+ {2a14f99d-81a1-432d-80da-6471eda85aaa}
+ UpdateManager
+
+
+
+
+ MSBuild:Compile
+ Designer
+
+
+
+
\ No newline at end of file
diff --git a/UpdateManager/Windows/UpdateWindow.xaml b/UpdateManager.WPF/Windows/UpdateWindow.xaml
similarity index 93%
rename from UpdateManager/Windows/UpdateWindow.xaml
rename to UpdateManager.WPF/Windows/UpdateWindow.xaml
index 08786f1..e7be73e 100644
--- a/UpdateManager/Windows/UpdateWindow.xaml
+++ b/UpdateManager.WPF/Windows/UpdateWindow.xaml
@@ -1,5 +1,5 @@
-
+
diff --git a/UpdateManager/Windows/UpdateWindow.xaml.cs b/UpdateManager.WPF/Windows/UpdateWindow.xaml.cs
similarity index 91%
rename from UpdateManager/Windows/UpdateWindow.xaml.cs
rename to UpdateManager.WPF/Windows/UpdateWindow.xaml.cs
index 0f69bf3..444ee87 100644
--- a/UpdateManager/Windows/UpdateWindow.xaml.cs
+++ b/UpdateManager.WPF/Windows/UpdateWindow.xaml.cs
@@ -4,7 +4,7 @@
using System.Windows;
using Microsoft.Win32;
-namespace CodeDead.UpdateManager.Windows
+namespace CodeDead.UpdateManager.WPF.Windows
{
///
///
@@ -100,6 +100,11 @@ public string DownloadButtonContent
/// The text that should be displayed to the user to ask whether or not the update should be executed or not after the download has completed
///
public string UpdateNowText { get; set; }
+
+ ///
+ /// Gets or sets whether the built-in downloading functionality should be used
+ ///
+ public bool UseDownloader { get; set; } = true;
#endregion
///
@@ -146,9 +151,24 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
/// The RoutedEventArgs
private void BtnDownload_OnClick(object sender, RoutedEventArgs e)
{
+ if (!UseDownloader)
+ {
+ try
+ {
+ System.Diagnostics.Process.Start(DownloadUrl);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+
+ Close();
+ return;
+ }
+
+ SaveFileDialog sfd = new SaveFileDialog();
try
{
- SaveFileDialog sfd = new SaveFileDialog();
string extension = DownloadUrl.Substring(DownloadUrl.Length - 3);
string filter = extension.ToUpper() + " file (*." + extension + ")|*." + extension;
sfd.Filter = filter;
diff --git a/UpdateManager.sln b/UpdateManager.sln
index 17e5e88..d30812c 100644
--- a/UpdateManager.sln
+++ b/UpdateManager.sln
@@ -3,22 +3,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateManager", "UpdateManager\UpdateManager.csproj", "{4E804EAD-446A-47CC-B231-0A6255B867A3}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateManager.Sample", "UpdateManager.Sample\UpdateManager.Sample.csproj", "{D03650D7-39E3-4424-88FB-9B537DC2B98A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateManager.Sample.WPF", "UpdateManager.Sample.WPF\UpdateManager.Sample.WPF.csproj", "{C9F196C9-2FF0-4DD2-9E8E-A7CFACBD2ECF}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateManager", "UpdateManager\UpdateManager.csproj", "{2A14F99D-81A1-432D-80DA-6471EDA85AAA}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateManager.WPF", "UpdateManager.WPF\UpdateManager.WPF.csproj", "{60EA74AD-AE82-4259-BA77-780C4BF9527D}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {4E804EAD-446A-47CC-B231-0A6255B867A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {4E804EAD-446A-47CC-B231-0A6255B867A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {4E804EAD-446A-47CC-B231-0A6255B867A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {4E804EAD-446A-47CC-B231-0A6255B867A3}.Release|Any CPU.Build.0 = Release|Any CPU
{D03650D7-39E3-4424-88FB-9B537DC2B98A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D03650D7-39E3-4424-88FB-9B537DC2B98A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D03650D7-39E3-4424-88FB-9B537DC2B98A}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -27,6 +25,14 @@ Global
{C9F196C9-2FF0-4DD2-9E8E-A7CFACBD2ECF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9F196C9-2FF0-4DD2-9E8E-A7CFACBD2ECF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9F196C9-2FF0-4DD2-9E8E-A7CFACBD2ECF}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2A14F99D-81A1-432D-80DA-6471EDA85AAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2A14F99D-81A1-432D-80DA-6471EDA85AAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2A14F99D-81A1-432D-80DA-6471EDA85AAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2A14F99D-81A1-432D-80DA-6471EDA85AAA}.Release|Any CPU.Build.0 = Release|Any CPU
+ {60EA74AD-AE82-4259-BA77-780C4BF9527D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {60EA74AD-AE82-4259-BA77-780C4BF9527D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {60EA74AD-AE82-4259-BA77-780C4BF9527D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {60EA74AD-AE82-4259-BA77-780C4BF9527D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/UpdateManager/Classes/Update.cs b/UpdateManager/Classes/Update.cs
deleted file mode 100644
index c7bb1a7..0000000
--- a/UpdateManager/Classes/Update.cs
+++ /dev/null
@@ -1,88 +0,0 @@
-using System;
-using System.Web.Script.Serialization;
-using System.Xml.Serialization;
-
-namespace CodeDead.UpdateManager.Classes
-{
- ///
- /// Class that represents an application update
- ///
- public sealed class Update
- {
- #region XML_Update
-
- ///
- /// The major version of the most current update
- ///
- public int MajorVersion;
-
- ///
- /// The minor version of the most current update
- ///
- public int MinorVersion;
-
- ///
- /// The build version of the most current update
- ///
- public int BuildVersion;
-
- ///
- /// The revision version of the most current update
- ///
- public int RevisionVersion;
-
- ///
- /// The update URL of the most current update
- ///
- public string UpdateUrl;
-
- ///
- /// The information URL of the most current update
- ///
- public string InfoUrl;
-
- ///
- /// The information in plain text regarding this update
- ///
- public string UpdateInfo;
-
- #endregion
-
- #region Assigned_Variables
-
- ///
- /// The current application version
- ///
- [XmlIgnore] [ScriptIgnore] private Version _applicationVersion;
-
- #endregion
-
- #region Properties
-
- ///
- /// Gets or sets the current application version
- ///
- [XmlIgnore]
- [ScriptIgnore]
- public Version ApplicationVersion
- {
- get => _applicationVersion;
- set => _applicationVersion = value ?? throw new ArgumentNullException(nameof(value));
- }
-
- #endregion
-
- ///
- /// Check whether or not there is an update available
- ///
- /// A boolean to represent whether there is an update available or not
- public bool CheckForUpdate()
- {
- if (ApplicationVersion == null) throw new ArgumentNullException(nameof(ApplicationVersion));
-
- int result = new Version(MajorVersion, MinorVersion, BuildVersion, RevisionVersion)
- .CompareTo(ApplicationVersion);
- return result > 0;
- }
- }
-}
diff --git a/UpdateManager/Classes/UpdateManager.cs b/UpdateManager/Classes/UpdateManager.cs
deleted file mode 100644
index 0fde6d7..0000000
--- a/UpdateManager/Classes/UpdateManager.cs
+++ /dev/null
@@ -1,213 +0,0 @@
-using System;
-using System.Net;
-using System.Threading.Tasks;
-using System.Windows;
-using CodeDead.UpdateManager.Classes.Utils;
-using CodeDead.UpdateManager.Windows;
-
-namespace CodeDead.UpdateManager.Classes
-{
- ///
- /// Class that has the ability to check for software updates
- ///
- public sealed class UpdateManager
- {
- #region Variables
-
- ///
- /// The URL that can be used to check for updates
- ///
- private string _updateUrl;
-
- ///
- /// The version of the application
- ///
- private Version _applicationVersion;
-
- ///
- /// The string variables that can be used to display information to the user
- ///
- private StringVariables _stringVariables;
-
- #endregion
-
- ///
- /// Initialize a new UpdateManager
- ///
- public UpdateManager()
- {
- StringVariables = new StringVariables();
- }
-
- ///
- /// Initiate a new UpdateManager object
- ///
- /// Your application version
- /// The URL where your XML update file is located
- /// StringVariables object containing strings that can be used to display information to the user
- /// The DataType that can be used to deserialize the update information
- public UpdateManager(Version version, string updateUrl, StringVariables stringVariables, DataType dataType)
- {
- UpdateUrl = updateUrl;
- DataType = dataType;
- ApplicationVersion = new Version(version.Major, version.Minor, version.Build, version.Revision);
- StringVariables = stringVariables;
- }
-
- ///
- /// Initiate a new UpdateManager object
- ///
- /// Your application version
- /// The URL where your XML update file is located
- /// StringVariables object containing strings that can be used to display information to the user
- /// The DataType that can be used to deserialize the update information
- /// Sets whether a dialog should be displayed when no updates are available
- public UpdateManager(Version version, string updateUrl, StringVariables stringVariables, DataType dataType,
- bool showNoUpdates)
- {
- UpdateUrl = updateUrl;
- DataType = dataType;
- ApplicationVersion = new Version(version.Major, version.Minor, version.Build, version.Revision);
- StringVariables = stringVariables;
- ShowNoUpdates = showNoUpdates;
- }
-
- ///
- /// Initialize a new UpdateManager object
- ///
- /// Your application version
- /// The URL where your XML update file is located
- /// The DataType that can be used to deserialize the update information
- public UpdateManager(Version version, string updateUrl, DataType dataType)
- {
- UpdateUrl = updateUrl;
- DataType = dataType;
- ApplicationVersion = new Version(version.Major, version.Minor, version.Build, version.Revision);
- StringVariables = new StringVariables();
- }
-
- #region Properties
-
- ///
- /// Gets or sets the DataType that can be used to deserialize the update information
- ///
- public DataType DataType { get; set; } = DataType.Json;
-
- ///
- /// Gets or sets the update URL
- ///
- public string UpdateUrl
- {
- get => _updateUrl;
- set => _updateUrl = value ?? throw new ArgumentNullException(nameof(value));
- }
-
- ///
- /// Gets or sets the local version of the application
- ///
- public Version ApplicationVersion
- {
- get => _applicationVersion;
- set => _applicationVersion = value ?? throw new ArgumentNullException(nameof(value));
- }
-
- ///
- /// Gets or sets whether a dialog should be displayed when no updates are available
- ///
- public bool ShowNoUpdates { get; set; } = true;
-
- ///
- /// Gets or sets the StringVariables object that contains translations
- ///
- public StringVariables StringVariables
- {
- get => _stringVariables;
- set => _stringVariables = value ?? throw new ArgumentNullException(nameof(value));
- }
-
- #endregion
-
- ///
- /// Retrieve the latest Update object
- ///
- public Update GetLatestVersion()
- {
- if (UpdateUrl == null) throw new ArgumentNullException(nameof(UpdateUrl));
- if (UpdateUrl.Length == 0) throw new ArgumentException(nameof(UpdateUrl));
-
- string data = new WebClient().DownloadString(UpdateUrl);
- Update update;
-
- // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
- switch (DataType)
- {
- default:
- update = UpdateDeserializer.DeserializeJson(data, ApplicationVersion);
- break;
- case DataType.Xml:
- update = UpdateDeserializer.DeserializeXml(data, ApplicationVersion);
- break;
- }
-
- return update;
- }
-
- ///
- /// Asynchronously retrieve the latest Update object
- ///
- public async Task GetLatestVersionAsync()
- {
- if (UpdateUrl == null) throw new ArgumentNullException(nameof(UpdateUrl));
- if (UpdateUrl.Length == 0) throw new ArgumentException(nameof(UpdateUrl));
-
- string data = await new WebClient().DownloadStringTaskAsync(UpdateUrl);
- Update update;
-
- // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
- switch (DataType)
- {
- default:
- update = await UpdateDeserializer.DeserializeJsonAsync(data, ApplicationVersion);
- break;
- case DataType.Xml:
- update = await UpdateDeserializer.DeserializeXmlAsync(data, ApplicationVersion);
- break;
- }
-
- return update;
- }
-
- ///
- /// Display an update dialog, if applicable
- ///
- /// The Update that contains the latest information regarding the version
- public void DisplayUpdateDialog(Update applicationUpdate)
- {
- if (applicationUpdate == null) throw new ArgumentNullException(nameof(applicationUpdate));
-
- if (applicationUpdate.CheckForUpdate())
- {
- UpdateWindow window = new UpdateWindow
- {
- Title = _stringVariables.TitleText,
- InformationTextBlockContent = applicationUpdate.UpdateInfo,
- InformationButtonContent = _stringVariables.InformationButtonText,
- CancelButtonContent = _stringVariables.CancelButtonText,
- DownloadButtonContent = _stringVariables.DownloadButtonText,
- DownloadUrl = applicationUpdate.UpdateUrl,
- InformationUrl = applicationUpdate.InfoUrl,
- UpdateNowText = _stringVariables.UpdateNowText
- };
- window.ShowDialog();
- }
- else
- {
- if (ShowNoUpdates)
- {
- MessageBox.Show(_stringVariables.NoNewVersionText, _stringVariables.TitleText, MessageBoxButton.OK,
- MessageBoxImage.Information);
- }
- }
- }
- }
-}
diff --git a/UpdateManager/Classes/DataType.cs b/UpdateManager/DataType.cs
similarity index 83%
rename from UpdateManager/Classes/DataType.cs
rename to UpdateManager/DataType.cs
index 9a126e1..53e8cfa 100644
--- a/UpdateManager/Classes/DataType.cs
+++ b/UpdateManager/DataType.cs
@@ -1,4 +1,4 @@
-namespace CodeDead.UpdateManager.Classes
+namespace CodeDead.UpdateManager
{
///
/// Enum that contains the different data types that are supported in order to deserialize the Update class
diff --git a/UpdateManager/Objects/PlatformUpdate.cs b/UpdateManager/Objects/PlatformUpdate.cs
new file mode 100644
index 0000000..43d1494
--- /dev/null
+++ b/UpdateManager/Objects/PlatformUpdate.cs
@@ -0,0 +1,79 @@
+using System;
+
+namespace CodeDead.UpdateManager.Objects
+{
+ ///
+ /// Class that contains the logic for a specific platform update
+ ///
+ public sealed class PlatformUpdate
+ {
+ #region Variables
+
+ private string _platformName;
+ private Update _update;
+
+ #endregion
+
+ ///
+ /// Initialize a new PlatformUpdate
+ ///
+ public PlatformUpdate()
+ {
+ PlatformName = "";
+ Update = new Update();
+ }
+
+ ///
+ /// Initialize a new PlatformUpdate
+ ///
+ /// The name of the platform for which the update applies
+ public PlatformUpdate(string platformName)
+ {
+ PlatformName = platformName;
+ Update = new Update();
+ }
+
+ ///
+ /// Initialize a new PlatformUpdate
+ ///
+ /// The Update object that corresponds to the current platform
+ public PlatformUpdate(Update update)
+ {
+ PlatformName = "";
+ Update = update;
+ }
+
+ ///
+ /// Initialize a new PlatformUpdate
+ ///
+ /// The name of the platform for which the update applies
+ /// The Update object that corresponds to the current platform
+ public PlatformUpdate(string platformName, Update update)
+ {
+ PlatformName = platformName;
+ Update = update;
+ }
+
+ #region Properties
+
+ ///
+ /// Gets or sets the platform name
+ ///
+ public string PlatformName
+ {
+ get => _platformName;
+ set => _platformName = value ?? throw new ArgumentNullException(nameof(value));
+ }
+
+ ///
+ /// Gets or sets the Update object
+ ///
+ public Update Update
+ {
+ get => _update;
+ set => _update = value ?? throw new ArgumentNullException(nameof(value));
+ }
+
+ #endregion
+ }
+}
diff --git a/UpdateManager/Objects/PlatformUpdates.cs b/UpdateManager/Objects/PlatformUpdates.cs
new file mode 100644
index 0000000..ead3bfa
--- /dev/null
+++ b/UpdateManager/Objects/PlatformUpdates.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Collections.Generic;
+
+namespace CodeDead.UpdateManager.Objects
+{
+ ///
+ /// Class that contains logic to retrieve updates for multiple platforms
+ ///
+ public sealed class PlatformUpdates
+ {
+ #region Variables
+
+ private List _platformUpdateList;
+
+ #endregion
+
+ ///
+ /// Initialize a new PlatformUpdates object
+ ///
+ public PlatformUpdates()
+ {
+ PlatformUpdateList = new List();
+ }
+
+ ///
+ /// Initialize a new PlatformUpdates object
+ ///
+ /// The list of PlatformUpdate objects
+ public PlatformUpdates(List platformUpdateList)
+ {
+ PlatformUpdateList = platformUpdateList;
+ }
+
+ #region Properties
+
+ ///
+ /// Gets or sets the list of platforms for which there are updates
+ ///
+ public List PlatformUpdateList
+ {
+ get => _platformUpdateList;
+ set => _platformUpdateList = value ?? throw new ArgumentNullException(nameof(value));
+ }
+
+ #endregion
+ }
+}
diff --git a/UpdateManager/Objects/Update.cs b/UpdateManager/Objects/Update.cs
new file mode 100644
index 0000000..738c553
--- /dev/null
+++ b/UpdateManager/Objects/Update.cs
@@ -0,0 +1,86 @@
+using System;
+
+namespace CodeDead.UpdateManager.Objects
+{
+ ///
+ /// Class that represents an application update
+ ///
+ public sealed class Update
+ {
+ ///
+ /// Initialize a new Update
+ ///
+ public Update()
+ {
+ // Empty constructor
+ }
+
+ ///
+ /// Initialize a new Update
+ ///
+ /// The major version of the most current update
+ /// The minor version of the most current update
+ /// The build version of the most current update
+ /// The revision version of the most current update
+ public Update(int majorVersion, int minorVersion, int buildVersion, int revisionVersion)
+ {
+ MajorVersion = majorVersion;
+ MinorVersion = minorVersion;
+ BuildVersion = buildVersion;
+ RevisionVersion = revisionVersion;
+ }
+
+ #region Properties
+
+ ///
+ /// Gets or sets he major version of the most current update
+ ///
+ public int MajorVersion { get; set; }
+
+ ///
+ /// Gets or sets the minor version of the most current update
+ ///
+ public int MinorVersion { get; set; }
+
+ ///
+ /// Gets or sets the build version of the most current update
+ ///
+ public int BuildVersion { get; set; }
+
+ ///
+ /// Gets or sets the revision version of the most current update
+ ///
+ public int RevisionVersion { get; set; }
+
+ ///
+ /// Gets or sets the update URL of the most current update
+ ///
+ public string UpdateUrl { get; set; }
+
+ ///
+ /// Gets or sets the information URL of the most current update
+ ///
+ public string InfoUrl { get; set; }
+
+ ///
+ /// Gets or sets the information in plain text regarding this update
+ ///
+ public string UpdateInfo { get; set; }
+
+ #endregion
+
+ ///
+ /// Check whether the application version is lower than the update version
+ ///
+ /// The current application version
+ /// True if an update is available, otherwise false
+ public bool UpdateAvailable(Version applicationVersion)
+ {
+ if (applicationVersion == null) throw new ArgumentNullException(nameof(applicationVersion));
+
+ int result = new Version(MajorVersion, MinorVersion, BuildVersion, RevisionVersion)
+ .CompareTo(applicationVersion);
+ return result > 0;
+ }
+ }
+}
diff --git a/UpdateManager/UpdateManager.cs b/UpdateManager/UpdateManager.cs
new file mode 100644
index 0000000..f5249ce
--- /dev/null
+++ b/UpdateManager/UpdateManager.cs
@@ -0,0 +1,219 @@
+using System;
+using System.Net;
+using System.Threading.Tasks;
+using CodeDead.UpdateManager.Objects;
+using CodeDead.UpdateManager.Utils;
+
+namespace CodeDead.UpdateManager
+{
+ ///
+ /// Class that has the ability to check for software updates
+ ///
+ public sealed class UpdateManager
+ {
+ #region Variables
+
+ ///
+ /// The URL that can be used to check for updates
+ ///
+ private string _updateUrl;
+
+ ///
+ /// The current application's platform
+ ///
+ private string _currentPlatform;
+
+ #endregion
+
+ ///
+ /// Initialize a new UpdateManager
+ ///
+ public UpdateManager()
+ {
+ // Empty constructor
+ }
+
+ ///
+ /// Initialize a new UpdateManager
+ ///
+ /// The current application's platform
+ public UpdateManager(string currentPlatform)
+ {
+ CurrentPlatform = currentPlatform;
+ }
+
+ ///
+ /// Initialize a new UpdateManager
+ ///
+ /// The current application's platform
+ /// The URL of the remote location where the PlatformUpdates can be retrieved
+ public UpdateManager(string currentPlatform, string updateUrl)
+ {
+ CurrentPlatform = currentPlatform;
+ UpdateUrl = updateUrl;
+ }
+
+ ///
+ /// Initialize a new UpdateManager
+ ///
+ /// The current application's platform
+ /// The URL of the remote location where the PlatformUpdates can be retrieved
+ /// The DataType that can be used to deserialize the update information
+ public UpdateManager(string currentPlatform, string updateUrl, DataType dataType)
+ {
+ CurrentPlatform = currentPlatform;
+ UpdateUrl = updateUrl;
+ DataType = dataType;
+ }
+
+ #region Properties
+
+ ///
+ /// Gets or sets the DataType that can be used to deserialize the update information
+ ///
+ public DataType DataType { get; set; } = DataType.Json;
+
+ ///
+ /// Gets or sets the update URL
+ ///
+ public string UpdateUrl
+ {
+ get => _updateUrl;
+ set => _updateUrl = value ?? throw new ArgumentNullException(nameof(value));
+ }
+
+ ///
+ /// Gets or sets the current platform
+ ///
+ public string CurrentPlatform
+ {
+ get => _currentPlatform;
+ set => _currentPlatform = value ?? throw new ArgumentNullException(nameof(value));
+ }
+
+ ///
+ /// Gets or sets the IWebProxy that can be used to retrieve data
+ ///
+ public IWebProxy WebProxy { get; set; }
+
+ ///
+ /// Gets or sets the WebHeaderCollection that can be used to retrieve data
+ ///
+ public WebHeaderCollection WebClientHeaders { get; set; }
+
+ #endregion
+
+ ///
+ /// Retrieve the latest PlatformUpdates object
+ ///
+ /// The PlatformUpdates object that was retrieved from a remote location
+ public PlatformUpdates GetLatestVersions()
+ {
+ if (UpdateUrl == null) throw new ArgumentNullException(nameof(UpdateUrl));
+ if (UpdateUrl.Length == 0) throw new ArgumentException(nameof(UpdateUrl));
+
+ string data;
+ using (WebClient wc = new WebClient())
+ {
+ wc.Proxy = WebProxy;
+ wc.Headers = WebClientHeaders;
+
+ data = wc.DownloadString(UpdateUrl);
+ }
+
+ PlatformUpdates updates;
+
+ // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
+ switch (DataType)
+ {
+ default:
+ updates = PlatformUpdatesDeserializer.DeserializeJson(data);
+ break;
+ case DataType.Xml:
+ updates = PlatformUpdatesDeserializer.DeserializeXml(data);
+ break;
+ }
+
+ return updates;
+ }
+
+ ///
+ /// Asynchronously retrieve the latest PlatformUpdates object
+ ///
+ /// The PlatformUpdates object that was retrieved from a remote location
+ public async Task GetLatestVersionsAsync()
+ {
+ if (UpdateUrl == null) throw new ArgumentNullException(nameof(UpdateUrl));
+ if (UpdateUrl.Length == 0) throw new ArgumentException(nameof(UpdateUrl));
+
+ string data;
+ using (WebClient wc = new WebClient())
+ {
+ wc.Proxy = WebProxy;
+ wc.Headers = WebClientHeaders;
+
+ data = await wc.DownloadStringTaskAsync(UpdateUrl);
+ }
+
+ PlatformUpdates updates;
+
+ // ReSharper disable once SwitchStatementHandlesSomeKnownEnumValuesWithDefault
+ switch (DataType)
+ {
+ default:
+ updates = await PlatformUpdatesDeserializer.DeserializeJsonAsync(data);
+ break;
+ case DataType.Xml:
+ updates = await PlatformUpdatesDeserializer.DeserializeXmlAsync(data);
+ break;
+ }
+
+ return updates;
+ }
+
+ ///
+ /// Retrieve the latest Update object
+ ///
+ /// The Update object that was retrieved from a remote location
+ public Update GetLatestVersion()
+ {
+ if (CurrentPlatform == null) throw new ArgumentNullException(nameof(CurrentPlatform));
+ if (CurrentPlatform.Length == 0) throw new ArgumentException(nameof(CurrentPlatform));
+
+ PlatformUpdates updates = GetLatestVersions();
+
+ foreach (PlatformUpdate platformUpdate in updates.PlatformUpdateList)
+ {
+ if (platformUpdate.PlatformName == CurrentPlatform)
+ return platformUpdate.Update;
+ }
+
+ return null;
+ }
+
+ ///
+ /// Asynchronously retrieve the latest Update object
+ ///
+ /// The Update object that was retrieved from a remote location
+ public async Task GetLatestVersionAsync()
+ {
+ if (CurrentPlatform == null) throw new ArgumentNullException(nameof(CurrentPlatform));
+ if (CurrentPlatform.Length == 0) throw new ArgumentException(nameof(CurrentPlatform));
+
+ PlatformUpdates updates = await GetLatestVersionsAsync();
+ Update update = null;
+
+ await Task.Run(() =>
+ {
+ foreach (PlatformUpdate platformUpdate in updates.PlatformUpdateList)
+ {
+ if (platformUpdate.PlatformName != CurrentPlatform) continue;
+ update = platformUpdate.Update;
+ break;
+ }
+ });
+
+ return update;
+ }
+ }
+}
diff --git a/UpdateManager/UpdateManager.csproj b/UpdateManager/UpdateManager.csproj
index 0dc083b..036f229 100644
--- a/UpdateManager/UpdateManager.csproj
+++ b/UpdateManager/UpdateManager.csproj
@@ -1,67 +1,18 @@
-
-
-
+
+
- Debug
- AnyCPU
- {4E804EAD-446A-47CC-B231-0A6255B867A3}
- Library
- Properties
- CodeDead.UpdateManager
+ netstandard2.0
CodeDead.UpdateManager
- v4.8
- 512
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
+ CodeDead.UpdateManager
-
+
+
none
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
+ false
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- UpdateWindow.xaml
-
-
-
-
-
- Designer
- MSBuild:Compile
-
+
-
-
\ No newline at end of file
+
+
diff --git a/UpdateManager/Classes/Utils/UpdateDeserializer.cs b/UpdateManager/Utils/PlatformUpdatesDeserializer.cs
similarity index 50%
rename from UpdateManager/Classes/Utils/UpdateDeserializer.cs
rename to UpdateManager/Utils/PlatformUpdatesDeserializer.cs
index 8ead3e5..f70cd1b 100644
--- a/UpdateManager/Classes/Utils/UpdateDeserializer.cs
+++ b/UpdateManager/Utils/PlatformUpdatesDeserializer.cs
@@ -1,111 +1,103 @@
using System;
using System.IO;
using System.Threading.Tasks;
-using System.Web.Script.Serialization;
using System.Xml.Serialization;
+using CodeDead.UpdateManager.Objects;
+using Newtonsoft.Json;
-namespace CodeDead.UpdateManager.Classes.Utils
+namespace CodeDead.UpdateManager.Utils
{
///
- /// Class that contains logic to deserialize an XML or JSON file to an Update object
+ /// Class that contains logic to deserialize an XML or JSON file to a PlatformUpdates object
///
- internal static class UpdateDeserializer
+ internal static class PlatformUpdatesDeserializer
{
///
- /// Deserialize XML data into an Update object
+ /// Deserialize XML data into a PlatformUpdates object
///
/// The XML data that should be deserialized
- /// The current Version of the application
- /// The Update object that was deserialized
- internal static Update DeserializeXml(string data, Version applicationVersion)
+ /// The PlatformUpdates object that was deserialized
+ internal static PlatformUpdates DeserializeXml(string data)
{
if (data == null) throw new ArgumentNullException(nameof(data));
if (data.Length == 0) throw new ArgumentException(nameof(data));
- Update update;
- XmlSerializer serializer = new XmlSerializer(typeof(Update));
+ PlatformUpdates updates;
+ XmlSerializer serializer = new XmlSerializer(typeof(PlatformUpdates));
using (MemoryStream stream = new MemoryStream())
{
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(data);
writer.Flush();
- }
- stream.Position = 0;
- update = (Update)serializer.Deserialize(stream);
- update.ApplicationVersion = applicationVersion;
+ stream.Position = 0;
+ updates = (PlatformUpdates)serializer.Deserialize(stream);
+ }
}
- return update;
+ return updates;
}
///
- /// Deserialize XML data into an Update object asynchronously
+ /// Deserialize XML data into a PlatformUpdates object asynchronously
///
/// The XML data that should be deserialized
- /// The current Version of the application
- /// The Update object that was deserialized or null if an error occurred
- internal static async Task DeserializeXmlAsync(string data, Version applicationVersion)
+ /// The PlatformUpdates object that was deserialized or null if an error occurred
+ internal static async Task DeserializeXmlAsync(string data)
{
if (data == null) throw new ArgumentNullException(nameof(data));
if (data.Length == 0) throw new ArgumentException(nameof(data));
- Update update = null;
+ PlatformUpdates updates = null;
await Task.Run(async () =>
{
- XmlSerializer serializer = new XmlSerializer(typeof(Update));
+ XmlSerializer serializer = new XmlSerializer(typeof(PlatformUpdates));
using (MemoryStream stream = new MemoryStream())
{
using (StreamWriter writer = new StreamWriter(stream))
{
await writer.WriteAsync(data);
await writer.FlushAsync();
- }
- stream.Position = 0;
- update = (Update)serializer.Deserialize(stream);
- update.ApplicationVersion = applicationVersion;
+ stream.Position = 0;
+ updates = (PlatformUpdates)serializer.Deserialize(stream);
+ }
}
- return update;
});
- return update;
+ return updates;
}
///
- /// Deserialize JSON data into an Update object
+ /// Deserialize JSON data into a PlatformUpdates object
///
/// The JSON data that should be deserialized
- /// The current Version of the application
- /// The Update object that was deserialized
- internal static Update DeserializeJson(string data, Version applicationVersion)
+ /// The PlatformUpdates object that was deserialized
+ internal static PlatformUpdates DeserializeJson(string data)
{
if (data == null) throw new ArgumentNullException(nameof(data));
if (data.Length == 0) throw new ArgumentException(nameof(data));
- Update update = new JavaScriptSerializer().Deserialize(data);
- update.ApplicationVersion = applicationVersion;
- return update;
+ PlatformUpdates updates = JsonConvert.DeserializeObject(data);
+ return updates;
}
///
- /// Deserialize JSON data into an Update object asynchronously
+ /// Deserialize JSON data into a PlatformUpdates object asynchronously
///
/// The JSON data that should be deserialized
- /// The current Version of the application
- /// The Update object that was deserialized
- internal static async Task DeserializeJsonAsync(string data, Version applicationVersion)
+ /// The PlatformUpdates object that was deserialized
+ internal static async Task DeserializeJsonAsync(string data)
{
if (data == null) throw new ArgumentNullException(nameof(data));
if (data.Length == 0) throw new ArgumentException(nameof(data));
- Update update = null;
+ PlatformUpdates updates = null;
await Task.Run(() =>
{
- update = new JavaScriptSerializer().Deserialize(data);
- update.ApplicationVersion = applicationVersion;
+ updates = JsonConvert.DeserializeObject(data);
});
- return update;
+ return updates;
}
}
}