Auto updater added
This commit is contained in:
9
PWAppUpdater/App.xaml
Normal file
9
PWAppUpdater/App.xaml
Normal file
@@ -0,0 +1,9 @@
|
||||
<Application x:Class="PWAppUpdater.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:PWAppUpdater"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
17
PWAppUpdater/App.xaml.cs
Normal file
17
PWAppUpdater/App.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace PWAppUpdater
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
||||
10
PWAppUpdater/AssemblyInfo.cs
Normal file
10
PWAppUpdater/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
45
PWAppUpdater/FTP/FTPManager.cs
Normal file
45
PWAppUpdater/FTP/FTPManager.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
|
||||
namespace PWAppUpdater.FTP
|
||||
{
|
||||
class FTPManager
|
||||
{
|
||||
private string BaseUri;
|
||||
private NetworkCredential credential;
|
||||
|
||||
public FTPManager(string baseUri, string username, string password)
|
||||
{
|
||||
BaseUri = baseUri;
|
||||
credential = new NetworkCredential(username, password);
|
||||
}
|
||||
|
||||
public void DownloadFile(string FTPPath, string localPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(BaseUri + FTPPath);
|
||||
request.Method = WebRequestMethods.Ftp.DownloadFile;
|
||||
request.Credentials = credential;
|
||||
request.KeepAlive = false;
|
||||
request.UseBinary = true;
|
||||
request.UsePassive = true;
|
||||
|
||||
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
|
||||
Stream responseStream = response.GetResponseStream();
|
||||
|
||||
using (Stream s = File.Create(localPath))
|
||||
{
|
||||
responseStream.CopyTo(s);
|
||||
}
|
||||
response.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
16
PWAppUpdater/MainWindow.xaml
Normal file
16
PWAppUpdater/MainWindow.xaml
Normal file
@@ -0,0 +1,16 @@
|
||||
<Window x:Class="PWAppUpdater.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:PWAppUpdater"
|
||||
mc:Ignorable="d"
|
||||
Title="PWUpdater" Height="137" Width="266">
|
||||
<Grid Margin="0,0,0,-4">
|
||||
<ProgressBar x:Name="barProgressBar" Minimum="0" Maximum="100" HorizontalAlignment="Center" Height="10" VerticalAlignment="Top" Width="246" Margin="0,46,0,0"/>
|
||||
<Label x:Name="statusText" Content="Please wait while the application is updating." HorizontalAlignment="Left" VerticalAlignment="Top"/>
|
||||
<Label x:Name="txtUpdateStep" Content="{Binding Path=txtUpdateStep}" HorizontalAlignment="Left" Margin="10,31,0,0" VerticalAlignment="Top"/>
|
||||
<Button x:Name="OKButton" Content="OK" HorizontalAlignment="Center" Margin="0,70,0,0" VerticalAlignment="Top" Click="Button_Click"/>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
46
PWAppUpdater/MainWindow.xaml.cs
Normal file
46
PWAppUpdater/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace PWAppUpdater
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
||||
statusText.Content = "The program will now be updated.\nPlease click \"OK\" to continue.";
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
OKButton.IsEnabled = false;
|
||||
for(int i = 0; i < 100; i++)
|
||||
{
|
||||
barProgressBar.Value = i;
|
||||
barProgressBar.UpdateLayout();
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
PWAppUpdater/PWAppUpdater.csproj
Normal file
14
PWAppUpdater/PWAppUpdater.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Config\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
52
PWAppUpdater/Updater.cs
Normal file
52
PWAppUpdater/Updater.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using PWAppUpdater.FTP;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace PWAppUpdater
|
||||
{
|
||||
class Updater
|
||||
{
|
||||
public static void Update(string installPath, string practiceConfigLocation = "", string tempPath = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
if (tempPath == "")
|
||||
{
|
||||
tempPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||
tempPath = Path.Combine(tempPath, "PWAPP\\Temp");
|
||||
}
|
||||
if (!Directory.Exists(tempPath))
|
||||
{
|
||||
Directory.CreateDirectory(tempPath);
|
||||
}
|
||||
FTP.FTPManager ftpManager = new FTPManager("ftp://waws-prod-blu-109.ftp.azurewebsites.windows.net/", "patientweb\\$patientweb", "vHBnkgxPDS4Q410eehaFlXb8DH67QW50m9Rsxf1omXyYWRDgYioWJL63Tagp");
|
||||
ftpManager.DownloadFile("pwapp/current/Release.zip", tempPath);
|
||||
|
||||
if (Directory.Exists(installPath))
|
||||
{
|
||||
Directory.Delete(installPath, true);
|
||||
}
|
||||
Directory.CreateDirectory(installPath);
|
||||
Zip.ZipManager.UnZip(tempPath, installPath, true);
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
MessageBox.Show("Updater does not have sufficent permissions to perform update. Please run with administrator privilages to continue.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class CouldNotFindInstallPathException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
28
PWAppUpdater/Zip/ZipManager.cs
Normal file
28
PWAppUpdater/Zip/ZipManager.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Compression;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PWAppUpdater.Zip
|
||||
{
|
||||
class ZipManager
|
||||
{
|
||||
public static void UnZip(string source, string destination, bool Override)
|
||||
{
|
||||
if (Override)
|
||||
{
|
||||
if (Directory.Exists(destination))
|
||||
{
|
||||
Directory.Delete(destination, true);
|
||||
}
|
||||
}
|
||||
|
||||
ZipFile.ExtractToDirectory(source, destination);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
9
PWAppUpdater/app.manifest
Normal file
9
PWAppUpdater/app.manifest
Normal file
@@ -0,0 +1,9 @@
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<security>
|
||||
<requestedPrivileges>
|
||||
<requestedExecutionLevel level="highestAvailable" />
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
</assembly>
|
||||
Reference in New Issue
Block a user