Skip to content

Commit 93eefe5

Browse files
committed
Installation
1 parent 5a892dd commit 93eefe5

File tree

85 files changed

+1998
-65
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1998
-65
lines changed

AutoSynthesis Updater/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

AutoSynthesis Updater/App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="AutoSynthesis_Updater.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:AutoSynthesis_Updater"
5+
StartupUri="AutoSynthesisUpdater.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>

AutoSynthesis Updater/App.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace AutoSynthesis_Updater
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{6116F2A7-C83A-482A-952A-2086165E558A}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>AutoSynthesis_Updater</RootNamespace>
10+
<AssemblyName>AutoSynthesis Updater</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
<Deterministic>true</Deterministic>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<PlatformTarget>AnyCPU</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<PlatformTarget>AnyCPU</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>..\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<PropertyGroup>
38+
<ApplicationIcon>icon.ico</ApplicationIcon>
39+
</PropertyGroup>
40+
<PropertyGroup>
41+
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
42+
</PropertyGroup>
43+
<ItemGroup>
44+
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
45+
<HintPath>..\RapidSynthesis\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
46+
</Reference>
47+
<Reference Include="System" />
48+
<Reference Include="System.Data" />
49+
<Reference Include="System.IO.Compression" />
50+
<Reference Include="System.IO.Compression.FileSystem" />
51+
<Reference Include="System.Xml" />
52+
<Reference Include="Microsoft.CSharp" />
53+
<Reference Include="System.Core" />
54+
<Reference Include="System.Xml.Linq" />
55+
<Reference Include="System.Data.DataSetExtensions" />
56+
<Reference Include="System.Net.Http" />
57+
<Reference Include="System.Xaml">
58+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
59+
</Reference>
60+
<Reference Include="WindowsBase" />
61+
<Reference Include="PresentationCore" />
62+
<Reference Include="PresentationFramework" />
63+
</ItemGroup>
64+
<ItemGroup>
65+
<ApplicationDefinition Include="App.xaml">
66+
<Generator>MSBuild:Compile</Generator>
67+
<SubType>Designer</SubType>
68+
</ApplicationDefinition>
69+
<Page Include="AutoSynthesisUpdater.xaml">
70+
<Generator>MSBuild:Compile</Generator>
71+
<SubType>Designer</SubType>
72+
</Page>
73+
<Compile Include="App.xaml.cs">
74+
<DependentUpon>App.xaml</DependentUpon>
75+
<SubType>Code</SubType>
76+
</Compile>
77+
<Compile Include="AutoSynthesisUpdater.xaml.cs">
78+
<DependentUpon>AutoSynthesisUpdater.xaml</DependentUpon>
79+
<SubType>Code</SubType>
80+
</Compile>
81+
</ItemGroup>
82+
<ItemGroup>
83+
<Compile Include="Classes\UpdateController.cs" />
84+
<Compile Include="DataTypes\UpdateMetadata.cs" />
85+
<Compile Include="Properties\AssemblyInfo.cs">
86+
<SubType>Code</SubType>
87+
</Compile>
88+
<Compile Include="Properties\Resources.Designer.cs">
89+
<AutoGen>True</AutoGen>
90+
<DesignTime>True</DesignTime>
91+
<DependentUpon>Resources.resx</DependentUpon>
92+
</Compile>
93+
<Compile Include="Properties\Settings.Designer.cs">
94+
<AutoGen>True</AutoGen>
95+
<DependentUpon>Settings.settings</DependentUpon>
96+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
97+
</Compile>
98+
<EmbeddedResource Include="Properties\Resources.resx">
99+
<Generator>ResXFileCodeGenerator</Generator>
100+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
101+
</EmbeddedResource>
102+
<None Include="packages.config" />
103+
<None Include="Properties\app.manifest" />
104+
<None Include="Properties\Settings.settings">
105+
<Generator>SettingsSingleFileGenerator</Generator>
106+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
107+
</None>
108+
</ItemGroup>
109+
<ItemGroup>
110+
<None Include="App.config" />
111+
</ItemGroup>
112+
<ItemGroup>
113+
<Resource Include="icon.ico" />
114+
</ItemGroup>
115+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
116+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Window x:Name="Updater" x:Class="AutoSynthesis_Updater.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:AutoSynthesis_Updater"
7+
mc:Ignorable="d"
8+
Title="AutoSynthesis Updater" SizeToContent="WidthAndHeight" ResizeMode="NoResize" Loaded="Updater_Loaded">
9+
<Grid Height="63" Width="352" Background="#FF1B1B1B">
10+
<ProgressBar x:Name="PGBUpdate" Height="28" Margin="5,29,5,0" VerticalAlignment="Top"/>
11+
<Label x:Name="LBLUpdate" Content="Updaing AutoSynthesis..." Height="26" Margin="5,3,5,0" VerticalAlignment="Top" VerticalContentAlignment="Center" Foreground="White"/>
12+
</Grid>
13+
</Window>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows;
7+
using System.Net;
8+
using System.Windows.Controls;
9+
using System.Windows.Data;
10+
using System.Windows.Documents;
11+
using System.Windows.Input;
12+
using System.Windows.Media;
13+
using System.Windows.Media.Imaging;
14+
using System.Windows.Navigation;
15+
using System.Windows.Shapes;
16+
17+
// TODO:
18+
// Ensure app is running in admin mode
19+
20+
21+
22+
namespace AutoSynthesis_Updater
23+
{
24+
/// <summary>
25+
/// Interaction logic for MainWindow.xaml
26+
/// Updates AutoSynthesis
27+
/// </summary>
28+
public partial class MainWindow : Window
29+
{
30+
public MainWindow()
31+
{
32+
InitializeComponent();
33+
}
34+
35+
private void Updater_Loaded(object sender, RoutedEventArgs e)
36+
{
37+
Task.Run(() =>
38+
{
39+
var updateController = new UpdateController(PGBUpdate);
40+
updateController.UpdateAutoSynthesis();
41+
42+
});
43+
}
44+
45+
46+
}
47+
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.IO;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
using System.Windows.Controls;
9+
using System.Windows.Data;
10+
using System.Windows.Documents;
11+
using System.Windows.Input;
12+
using System.Windows.Media;
13+
using System.Windows.Media.Imaging;
14+
using System.Windows.Navigation;
15+
using System.Windows.Shapes;
16+
using System.Threading;
17+
using System.Diagnostics;
18+
using System.Net;
19+
using Newtonsoft.Json;
20+
21+
namespace AutoSynthesis_Updater
22+
{
23+
class UpdateController
24+
{
25+
#region Properties
26+
// UI Elements
27+
private ProgressBar PGBUpdate { get; set; }
28+
29+
// Arguments
30+
private const string Arguments = "-isupdated";
31+
32+
// URLs
33+
private string UpdateMetadataURL { get; set; }
34+
private string AutoSynthesisFileName { get; set; } = "AutoSynthesis.exe";
35+
private string BaseURL { get; set; }
36+
37+
// Data Objects
38+
private UpdateMetadata UpdateMD { get; set; }
39+
#endregion
40+
41+
public UpdateController(ProgressBar pGBUpdate)
42+
{
43+
PGBUpdate = pGBUpdate;
44+
string path = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
45+
BaseURL = System.IO.Path.GetDirectoryName(path).Replace(@"file:\", "") + @"\";
46+
47+
if (Debugger.IsAttached)
48+
UpdateMetadataURL = "https://autosynthesis.blob.core.windows.net/autosynthesis/Dev/AutoSynthesisUpdate.json";
49+
else
50+
UpdateMetadataURL = "https://autosynthesis.blob.core.windows.net/autosynthesis/Releases/AutoSynthesisUpdate.json";
51+
52+
53+
}
54+
55+
public void UpdateAutoSynthesis()
56+
{
57+
// PROCESS:
58+
// Download update version update doc (json file)
59+
// Check Current AutoSynthesis Version
60+
// If Autosynth version is lower than the doc version, initiate update
61+
// Download the files with version files
62+
// Extract files in current folder overwriting existing files
63+
64+
try
65+
{
66+
67+
// Download JSON File with Metadata for the Update
68+
GetUpdateMetadata();
69+
// Get Current version added to UpdateMD
70+
GetCurrentVersion();
71+
72+
// If Current Version is up to date, terminate
73+
if (UpdateMD.CurrentVersion == UpdateMD.UpdateVersion)
74+
return;
75+
76+
// Download Most Recent File From UpdaterJson
77+
GetUpdateFiles();
78+
}
79+
finally
80+
{
81+
Thread.Sleep(1000);
82+
var url = BaseURL + AutoSynthesisFileName;
83+
Process.Start(url, Arguments);
84+
PGBUpdate.Dispatcher.Invoke(() => { Application.Current.Shutdown(); });
85+
}
86+
87+
88+
}
89+
90+
#region Get Metadata Information
91+
/// <summary>
92+
/// Aquire the Metadata information from Azure
93+
/// </summary>
94+
private void GetUpdateMetadata()
95+
{
96+
Log("Getting Metadata");
97+
var startTime = DateTime.Now;
98+
99+
string contents;
100+
using (var webClient = new WebClient())
101+
{
102+
contents = webClient.DownloadString(UpdateMetadataURL);
103+
}
104+
105+
UpdateMD = JsonConvert.DeserializeObject<UpdateMetadata>(contents);
106+
107+
var diff = (DateTime.Now - startTime).TotalMilliseconds;
108+
Log($"Metadata Aquired in {diff}ms");
109+
}
110+
111+
/// <summary>
112+
/// Aquire version information for existing application
113+
/// </summary>
114+
private void GetCurrentVersion()
115+
{
116+
Log("Getting Current Version Info");
117+
try
118+
{
119+
var currentAutoSynthesisVersion = FileVersionInfo.GetVersionInfo(BaseURL + AutoSynthesisFileName);
120+
UpdateMD.CurrentVersion = currentAutoSynthesisVersion.FileVersion.ToString();
121+
Log("Current AutoSynthesis Version Aquired: " + UpdateMD.CurrentVersion);
122+
}
123+
catch
124+
{
125+
Log("File Not Found");
126+
UpdateMD.CurrentVersion = "null";
127+
}
128+
}
129+
#endregion
130+
131+
#region Download Update Files
132+
private void GetUpdateFiles()
133+
{
134+
foreach(var key in UpdateMD.UpdateFiles.Keys)
135+
{
136+
var fileName = key;
137+
var fileURL = UpdateMD.UpdateFiles[key];
138+
139+
Log("Downloading Files for New Version " + UpdateMD.UpdateVersion);
140+
var time = DateTime.Now;
141+
142+
var downloadedUpdateUrl = BaseURL + fileName;
143+
using (var webClient = new WebClient())
144+
{
145+
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
146+
webClient.DownloadFileAsync(new Uri(fileURL), downloadedUpdateUrl);
147+
}
148+
149+
var diff = (DateTime.Now - time).TotalMilliseconds;
150+
Log($"File Downloaded in {diff}ms");
151+
}
152+
153+
}
154+
155+
private void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
156+
{
157+
double bytesIn = double.Parse(e.BytesReceived.ToString());
158+
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
159+
double percentage = bytesIn / totalBytes * 100;
160+
PGBUpdate.Dispatcher.Invoke(() => { PGBUpdate.Value = int.Parse(Math.Truncate(percentage).ToString()); });
161+
162+
}
163+
164+
#endregion
165+
166+
167+
#region Logging Method
168+
private void Log(string content)
169+
{
170+
Console.WriteLine(DateTime.Now + " - " + content);
171+
}
172+
#endregion
173+
}
174+
}

0 commit comments

Comments
 (0)