-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a20ef5
commit c23c01b
Showing
8 changed files
with
424 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,3 @@ | ||
.vs | ||
WindowsGSM-Updater/bin/ | ||
WindowsGSM-Updater/obj/ |
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29609.76 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsGSM-Updater", "WindowsGSM-Updater\WindowsGSM-Updater.csproj", "{2D539FC1-C23C-4FC1-90C3-1C487A657615}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{2D539FC1-C23C-4FC1-90C3-1C487A657615}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2D539FC1-C23C-4FC1-90C3-1C487A657615}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2D539FC1-C23C-4FC1-90C3-1C487A657615}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2D539FC1-C23C-4FC1-90C3-1C487A657615}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {AAC11572-8F6E-41B2-9C74-47D25231BD0D} | ||
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
</startup> | ||
</configuration> |
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,209 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Net; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace WindowsGSM_Updater | ||
{ | ||
/// <summary> | ||
/// A small console program to update WindowsGSM | ||
/// </summary> | ||
class Program | ||
{ | ||
private static string _wgsmPath; | ||
|
||
static void Main(string[] args) | ||
{ | ||
_wgsmPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, "..", "WindowsGSM.exe")); | ||
|
||
if (!File.Exists(_wgsmPath)) | ||
{ | ||
Console.WriteLine($"WindowsGSM.exe not found in ({_wgsmPath})"); | ||
Console.ReadLine(); | ||
Environment.Exit(-1); | ||
} | ||
|
||
#region Check Launch Param | ||
bool autostart = false, forceupdate = false; | ||
|
||
foreach (string arg in args) | ||
{ | ||
switch (arg) | ||
{ | ||
case "-autostart": autostart = true; break; | ||
case "-forceupdate": forceupdate = true; break; | ||
} | ||
} | ||
#endregion | ||
|
||
#region Compare Version | ||
if (!forceupdate) | ||
{ | ||
Console.WriteLine("Local version:"); | ||
Console.ForegroundColor = ConsoleColor.Green; | ||
string localVersion = GetLocalVersion(); | ||
Console.WriteLine(localVersion); | ||
Console.ResetColor(); | ||
|
||
Console.WriteLine("Latest version:"); | ||
Console.ForegroundColor = ConsoleColor.Green; | ||
string latestVersion = GetLatestVersion(); | ||
Console.WriteLine(latestVersion); | ||
Console.ResetColor(); | ||
|
||
Console.WriteLine(); | ||
|
||
if (localVersion == latestVersion) | ||
{ | ||
Console.WriteLine("WindowsGSM is up to date."); | ||
Console.ReadLine(); | ||
Environment.Exit(0); | ||
} | ||
else | ||
{ | ||
Console.Write($"{latestVersion} is available, do you want to update WindowsGSM? [Y/n]"); | ||
Console.Out.Flush(); | ||
var responce = Console.ReadLine(); | ||
|
||
if (!string.IsNullOrEmpty(responce) && responce.Trim().ToUpper() != "Y") | ||
{ | ||
Environment.Exit(-1); | ||
} | ||
} | ||
} | ||
#endregion | ||
|
||
#region Delete and Download | ||
Console.WriteLine(); | ||
Console.WriteLine("Deleting WindowsGSM.exe..."); | ||
DeleteWindowsGSM().Wait(); | ||
|
||
if (File.Exists(_wgsmPath)) | ||
{ | ||
Console.WriteLine("Fail to delete WindowsGSM.exe. Reason: File In Use"); | ||
Console.ReadLine(); | ||
Environment.Exit(-1); | ||
} | ||
|
||
Console.WriteLine("Downloading WindowsGSM.exe..."); | ||
DownloadWindowsGSM().Wait(); | ||
|
||
if (!File.Exists(_wgsmPath)) | ||
{ | ||
Console.WriteLine("Fail to download WindowsGSM.exe"); | ||
Console.ReadLine(); | ||
Environment.Exit(-1); | ||
} | ||
#endregion | ||
|
||
#region Update End + Action | ||
Console.WriteLine(); | ||
Console.WriteLine("WindowsGSM.exe updated successfully."); | ||
|
||
if (autostart) | ||
{ | ||
ProcessStartInfo psi = new ProcessStartInfo | ||
{ | ||
FileName = _wgsmPath, | ||
Verb = "runas" | ||
}; | ||
|
||
Process.Start(psi); | ||
} | ||
else | ||
{ | ||
Console.ReadLine(); | ||
} | ||
|
||
Environment.Exit(0); | ||
#endregion | ||
} | ||
|
||
private static string GetLocalVersion() | ||
{ | ||
string version = FileVersionInfo.GetVersionInfo(_wgsmPath).ProductVersion.ToString(); | ||
return $"v{version.Substring(0, version.Length - 2)}"; | ||
} | ||
|
||
private static string GetLatestVersion() | ||
{ | ||
if (WebRequest.Create("https://api.github.com/repos/WindowsGSM/WindowsGSM/releases/latest") is HttpWebRequest webRequest) | ||
{ | ||
webRequest.Method = "GET"; | ||
webRequest.UserAgent = "Anything"; | ||
webRequest.ServicePoint.Expect100Continue = false; | ||
|
||
try | ||
{ | ||
using (var responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream())) | ||
{ | ||
string json = responseReader.ReadToEnd(); | ||
Regex regex = new Regex("\"tag_name\":\"(.*?)\""); | ||
var matches = regex.Matches(json); | ||
|
||
if (matches.Count == 1 && matches[0].Groups.Count == 2) | ||
{ | ||
return matches[0].Groups[1].Value; | ||
} | ||
} | ||
} | ||
catch | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private static async Task<bool> DeleteWindowsGSM() | ||
{ | ||
await Task.Run(() => | ||
{ | ||
for (int i = 0; i < 5; i++) | ||
{ | ||
try | ||
{ | ||
if (File.Exists(_wgsmPath)) | ||
{ | ||
File.Delete(_wgsmPath); | ||
|
||
break; | ||
} | ||
} | ||
catch | ||
{ | ||
//ignore | ||
} | ||
|
||
Task.Delay(500); | ||
} | ||
}); | ||
|
||
return File.Exists(_wgsmPath); | ||
} | ||
|
||
private static async Task<bool> DownloadWindowsGSM() | ||
{ | ||
try | ||
{ | ||
using (WebClient webClient = new WebClient()) | ||
{ | ||
await webClient.DownloadFileTaskAsync("https://github.com/BattlefieldDuck/WindowsGSM/releases/latest/download/WindowsGSM.exe", _wgsmPath); | ||
} | ||
|
||
return true; | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
Console.WriteLine($"Error {e}"); | ||
Console.ResetColor(); | ||
|
||
return false; | ||
} | ||
} | ||
} | ||
} |
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,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// 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("WindowsGSM-Updater")] | ||
[assembly: AssemblyDescription("A small console program to update WindowsGSM")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("TatLead")] | ||
[assembly: AssemblyProduct("WindowsGSM-Updater")] | ||
[assembly: AssemblyCopyright("Copyright © 2020")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("2d539fc1-c23c-4fc1-90c3-1c487a657615")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// 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.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
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,69 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{2D539FC1-C23C-4FC1-90C3-1C487A657615}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>WindowsGSM_Updater</RootNamespace> | ||
<AssemblyName>WindowsGSM-Updater</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Prefer32Bit>false</Prefer32Bit> | ||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<ApplicationIcon>WindowsGSM.ico</ApplicationIcon> | ||
</PropertyGroup> | ||
<PropertyGroup /> | ||
<PropertyGroup> | ||
<ApplicationManifest>app.manifest</ApplicationManifest> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<StartupObject>WindowsGSM_Updater.Program</StartupObject> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
<None Include="app.manifest" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="WindowsGSM.ico" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
Binary file not shown.
Oops, something went wrong.