-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoUpdate.Net intial commit with version 1.1
- Loading branch information
0 parents
commit 27f2960
Showing
29 changed files
with
2,809 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoUpdater.NET", "AutoUpdater.NET\AutoUpdater.NET.csproj", "{FB9E7E6B-B19F-4F37-A708-2996190CEF13}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoUpdaterTest", "..\AutoUpdaterTest\AutoUpdaterTest\AutoUpdaterTest.csproj", "{FD5AE762-C630-49F8-B814-FCF70E7838D1}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|Mixed Platforms = Debug|Mixed Platforms | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|Mixed Platforms = Release|Mixed Platforms | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU | ||
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU | ||
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU | ||
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Release|Mixed Platforms.Build.0 = Release|Any CPU | ||
{FB9E7E6B-B19F-4F37-A708-2996190CEF13}.Release|x86.ActiveCfg = Release|Any CPU | ||
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|Any CPU.ActiveCfg = Debug|x86 | ||
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 | ||
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|Mixed Platforms.Build.0 = Debug|x86 | ||
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|x86.ActiveCfg = Debug|x86 | ||
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Debug|x86.Build.0 = Debug|x86 | ||
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Release|Any CPU.ActiveCfg = Release|x86 | ||
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Release|Mixed Platforms.ActiveCfg = Release|x86 | ||
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Release|Mixed Platforms.Build.0 = Release|x86 | ||
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Release|x86.ActiveCfg = Release|x86 | ||
{FD5AE762-C630-49F8-B814-FCF70E7838D1}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http:https://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{FB9E7E6B-B19F-4F37-A708-2996190CEF13}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>AutoUpdaterDotNET</RootNamespace> | ||
<AssemblyName>AutoUpdater.NET</AssemblyName> | ||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="AutoUpdater.cs" /> | ||
<Compile Include="DownloadUpdateDialog.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
<Compile Include="DownloadUpdateDialog.Designer.cs"> | ||
<DependentUpon>DownloadUpdateDialog.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="RemindLaterForm.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
<Compile Include="RemindLaterForm.Designer.cs"> | ||
<DependentUpon>RemindLaterForm.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="UpdateForm.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
<Compile Include="UpdateForm.Designer.cs"> | ||
<DependentUpon>UpdateForm.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DesignTime>True</DesignTime> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="DownloadUpdateDialog.resx"> | ||
<DependentUpon>DownloadUpdateDialog.cs</DependentUpon> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="RemindLaterForm.resx"> | ||
<DependentUpon>RemindLaterForm.cs</DependentUpon> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="UpdateForm.resx"> | ||
<DependentUpon>UpdateForm.cs</DependentUpon> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\download.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\clock_go.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\hand_point.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\download1.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\update.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\clock_go1.png" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\clock_play.png" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
using System; | ||
using System.Net; | ||
using System.IO; | ||
using System.Xml; | ||
using System.Reflection; | ||
using Microsoft.Win32; | ||
using System.ComponentModel; | ||
using System.Threading; | ||
|
||
namespace AutoUpdaterDotNET | ||
{ | ||
public class AutoUpdater | ||
{ | ||
|
||
private static String _title; | ||
|
||
private static String _changeLogUrl; | ||
|
||
private static String _downloadUrl; | ||
|
||
private static String _appCastUrl; | ||
|
||
private static String _appTitle; | ||
|
||
private static Version _currentVersion; | ||
|
||
private static Version _installedVersion; | ||
|
||
private static int _remindLaterAt; | ||
|
||
private static String _appCompany; | ||
|
||
private static String _registryLocation; | ||
|
||
private static Boolean _letUserSelectRemindLater; | ||
|
||
public enum RemindLaterFormat | ||
{ | ||
Minutes, | ||
Hours, | ||
Days | ||
} | ||
|
||
private static RemindLaterFormat _remindLaterFormat; | ||
|
||
public static void Start(String appCast, bool letUserSelectRemindLater = true, int remindLaterAt = 1, RemindLaterFormat remindLaterFormat = RemindLaterFormat.Days) | ||
{ | ||
_appCastUrl = appCast; | ||
_remindLaterAt = remindLaterAt; | ||
_remindLaterFormat = remindLaterFormat; | ||
_letUserSelectRemindLater = letUserSelectRemindLater; | ||
|
||
var backgroundWorker = new BackgroundWorker(); | ||
|
||
backgroundWorker.DoWork += BackgroundWorkerDoWork; | ||
|
||
backgroundWorker.RunWorkerAsync(); | ||
} | ||
|
||
public static void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) | ||
{ | ||
_appTitle = Assembly.GetEntryAssembly().GetName().Name; | ||
|
||
Assembly currentAssembly = typeof(AutoUpdater).Assembly; | ||
object[] attribs = currentAssembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true); | ||
if(attribs.Length > 0) | ||
{ | ||
_appCompany = ((AssemblyCompanyAttribute)attribs[0]).Company; | ||
} | ||
|
||
if (!string.IsNullOrEmpty(_appCompany)) | ||
_registryLocation = "Software\\" + _appCompany + "\\" + _appTitle + "\\AutoUpdater"; | ||
|
||
RegistryKey updateKey = Registry.CurrentUser.OpenSubKey(_registryLocation); | ||
|
||
if (updateKey != null) | ||
{ | ||
object remindLaterTime = updateKey.GetValue("remindlater"); | ||
|
||
if (remindLaterTime != null) | ||
{ | ||
DateTime remindLater = DateTime.Parse(remindLaterTime.ToString()); | ||
|
||
int compareResult = DateTime.Compare(DateTime.Now, remindLater); | ||
|
||
if (compareResult < 0) | ||
{ | ||
new UpdateForm(remindLater, _appCastUrl, _registryLocation, _remindLaterAt, _remindLaterFormat, _letUserSelectRemindLater); | ||
|
||
return; | ||
} | ||
} | ||
} | ||
|
||
_installedVersion = Assembly.GetEntryAssembly().GetName().Version; | ||
|
||
WebRequest webRequest = WebRequest.Create(_appCastUrl); | ||
|
||
WebResponse webResponse; | ||
|
||
try | ||
{ | ||
webResponse = webRequest.GetResponse(); | ||
} | ||
catch (Exception) | ||
{ | ||
return; | ||
} | ||
|
||
Stream appCastStream = webResponse.GetResponseStream(); | ||
|
||
var receivedAppCastDocument = new XmlDocument(); | ||
|
||
if (appCastStream != null) receivedAppCastDocument.Load(appCastStream); | ||
else return; | ||
|
||
XmlNodeList appCastItems = receivedAppCastDocument.SelectNodes("item"); | ||
|
||
if (appCastItems != null) | ||
foreach (XmlNode item in appCastItems) | ||
{ | ||
XmlNode appCastVersion = item.SelectSingleNode("version"); | ||
if (appCastVersion != null) | ||
{ | ||
String appVersion = appCastVersion.InnerText; | ||
var version = new Version(appVersion); | ||
if (version <= _installedVersion) | ||
continue; | ||
_currentVersion = version; | ||
} | ||
else | ||
continue; | ||
|
||
XmlNode appCastTitle = item.SelectSingleNode("title"); | ||
|
||
_title = appCastTitle != null ? appCastTitle.InnerText : ""; | ||
|
||
XmlNode appCastChangeLog = item.SelectSingleNode("changelog"); | ||
|
||
_changeLogUrl = appCastChangeLog != null ? appCastChangeLog.InnerText : ""; | ||
|
||
XmlNode appCastUrl = item.SelectSingleNode("url"); | ||
|
||
_downloadUrl = appCastUrl != null ? appCastUrl.InnerText : ""; | ||
} | ||
|
||
if (updateKey != null) | ||
{ | ||
object skip = updateKey.GetValue("skip"); | ||
object applicationVersion = updateKey.GetValue("version"); | ||
if (skip != null && applicationVersion != null) | ||
{ | ||
string skipValue = skip.ToString(); | ||
var skipVersion = new Version(applicationVersion.ToString()); | ||
if (skipValue.Equals("1") && _currentVersion <= skipVersion) | ||
return; | ||
if (_currentVersion > skipVersion) | ||
{ | ||
RegistryKey updateKeyWrite = Registry.CurrentUser.CreateSubKey(_registryLocation); | ||
updateKeyWrite.SetValue("version", _currentVersion.ToString()); | ||
updateKeyWrite.SetValue("skip", 0); | ||
} | ||
} | ||
updateKey.Close(); | ||
} | ||
|
||
if (_currentVersion == null) | ||
return; | ||
|
||
if (_currentVersion > _installedVersion) | ||
{ | ||
var thread = new Thread(ShowUi); | ||
thread.SetApartmentState(ApartmentState.STA); | ||
thread.Start(); | ||
} | ||
} | ||
|
||
private static void ShowUi() | ||
{ | ||
var updateForm = new UpdateForm(_title, _appCastUrl, _appTitle, _currentVersion, _installedVersion, _changeLogUrl, _downloadUrl, _registryLocation, _remindLaterAt, _remindLaterFormat, _letUserSelectRemindLater); | ||
|
||
updateForm.ShowDialog(); | ||
} | ||
} | ||
} |
Oops, something went wrong.