Skip to content

Commit f4a5ae0

Browse files
committed
v0.4 initial commit
1 parent 2914cc5 commit f4a5ae0

File tree

59 files changed

+13486
-518
lines changed

Some content is hidden

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

59 files changed

+13486
-518
lines changed

ACC Setup Wizard/ACC Setup Wizard.vdproj

Lines changed: 1078 additions & 0 deletions
Large diffs are not rendered by default.

ACC.sln

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 14
4-
VisualStudioVersion = 14.0.25420.1
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27428.2043
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssistantComputerControl", "AssistantComputerControl\AssistantComputerControl.csproj", "{404B42F4-E135-4D2F-8FD0-20A590814930}"
77
EndProject
8+
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "ACC Setup Wizard", "ACC Setup Wizard\ACC Setup Wizard.vdproj", "{B22F810A-C7C8-40FF-80B0-C3DBAC09FAD2}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
13+
DefaultBuild|Any CPU = DefaultBuild|Any CPU
1114
Release|Any CPU = Release|Any CPU
1215
EndGlobalSection
1316
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1417
{404B42F4-E135-4D2F-8FD0-20A590814930}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
1518
{404B42F4-E135-4D2F-8FD0-20A590814930}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{404B42F4-E135-4D2F-8FD0-20A590814930}.DefaultBuild|Any CPU.ActiveCfg = Debug|Any CPU
20+
{404B42F4-E135-4D2F-8FD0-20A590814930}.DefaultBuild|Any CPU.Build.0 = Debug|Any CPU
1621
{404B42F4-E135-4D2F-8FD0-20A590814930}.Release|Any CPU.ActiveCfg = Release|Any CPU
1722
{404B42F4-E135-4D2F-8FD0-20A590814930}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{B22F810A-C7C8-40FF-80B0-C3DBAC09FAD2}.Debug|Any CPU.ActiveCfg = Debug
24+
{B22F810A-C7C8-40FF-80B0-C3DBAC09FAD2}.DefaultBuild|Any CPU.ActiveCfg = Debug
25+
{B22F810A-C7C8-40FF-80B0-C3DBAC09FAD2}.Release|Any CPU.ActiveCfg = Release
1826
EndGlobalSection
1927
GlobalSection(SolutionProperties) = preSolution
2028
HideSolutionNode = FALSE
2129
EndGlobalSection
30+
GlobalSection(ExtensibilityGlobals) = postSolution
31+
SolutionGuid = {40F865E1-4CE6-4506-8E03-D47D76F46F57}
32+
EndGlobalSection
2233
EndGlobal

AssistantComputerControl/ACC_Updater.cs

Lines changed: 132 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,154 @@
22
using System.Windows.Forms;
33
using System.Net;
44
using System.Diagnostics;
5+
using Newtonsoft.Json;
6+
using System;
57

68
namespace AssistantComputerControl {
79
class ACC_Updater {
8-
public void Check() {
9-
string latest_version;
10-
using (WebClient client = new WebClient()) {
11-
latest_version = client.DownloadString("http://gh.albe.pw/acc/releases/latest/version.txt");
10+
private const string releaseJsonUrl = "http://acc.albe.pw/versions/release/latest_version.json";
11+
private const string betaJsonUrl = "http://acc.albe.pw/versions/beta/latest_version.json";
12+
13+
public bool Check() {
14+
MainProgram.DoDebug("Checking for updates...");
15+
16+
string latestReleaseJson = null;
17+
string latestBetaJson = null;
18+
19+
//Check and get latest
20+
if (RemoteFileExists(releaseJsonUrl)) {
21+
using (WebClient client = new WebClient()) {
22+
latestReleaseJson = client.DownloadString(releaseJsonUrl);
23+
}
1224
}
13-
if (latest_version != MainProgram.softwareVersion) {
14-
//New version available
15-
MainProgram.DoDebug("New software version found (" + latest_version + ")");
16-
DialogResult dialogResult = MessageBox.Show("A new version of " + MainProgram.messageBoxTitle + " is available (v" + latest_version + "), do you wish to install it?", "New update found | " + MainProgram.messageBoxTitle, MessageBoxButtons.YesNo);
17-
if (dialogResult == DialogResult.Yes) {
18-
MainProgram.DoDebug("User chose \"yes\" to install update");
19-
Install();
20-
} else if(dialogResult == DialogResult.No) {
21-
MainProgram.DoDebug("User did not want to install update");
25+
26+
//Check and get beta
27+
if (Properties.Settings.Default.BetaProgram && RemoteFileExists(betaJsonUrl)) {
28+
using (WebClient client = new WebClient()) {
29+
latestBetaJson = client.DownloadString(betaJsonUrl);
30+
}
31+
}
32+
33+
if (latestReleaseJson != null || latestBetaJson != null) {
34+
Version newVersion = null
35+
, latestRelease
36+
, latestBeta;
37+
38+
if (latestReleaseJson != null && latestBetaJson != null) {
39+
//Beta program enabled; check both release and beta for newest update
40+
latestRelease = JsonConvert.DeserializeObject<Version>(latestReleaseJson);
41+
latestBeta = JsonConvert.DeserializeObject<Version>(latestBetaJson);
42+
43+
if (DateTime.Parse(latestRelease.datetime) > DateTime.Parse(MainProgram.releaseDate) || DateTime.Parse(latestBeta.datetime) > DateTime.Parse(MainProgram.releaseDate)) {
44+
//Both latest release and beta is ahead of this current build
45+
if (DateTime.Parse(latestRelease.datetime) > DateTime.Parse(latestBeta.datetime)) {
46+
//Release is newest
47+
newVersion = latestRelease;
48+
} else {
49+
//Beta is newest
50+
newVersion = latestBeta;
51+
}
52+
} else {
53+
//None of them are newer. Nothing new
54+
MainProgram.DoDebug("Software up to date (beta program enabled)");
55+
return false;
56+
}
57+
} else if (latestReleaseJson != null && latestBetaJson == null) {
58+
//Only check latest
59+
latestRelease = JsonConvert.DeserializeObject<Version>(latestReleaseJson);
60+
61+
if (DateTime.Parse(latestRelease.datetime) > DateTime.Parse(MainProgram.releaseDate)) {
62+
//Newer build
63+
newVersion = latestRelease;
64+
} else {
65+
//Not new, move on
66+
MainProgram.DoDebug("Software up to date");
67+
return false;
68+
}
69+
} else if (latestReleaseJson == null && latestBetaJson != null) {
70+
//Couldn't reach "latest" update, but beta-updates are enabled
71+
latestBeta = JsonConvert.DeserializeObject<Version>(latestBetaJson);
72+
73+
if (DateTime.Parse(latestBeta.datetime) > DateTime.Parse(MainProgram.releaseDate)) {
74+
//Newer build
75+
newVersion = latestBeta;
76+
} else {
77+
//Not new, move on
78+
MainProgram.DoDebug("Software up to date (beta program enabled)");
79+
return false;
80+
}
81+
}
82+
83+
if (newVersion != null) {
84+
//New version available
85+
MainProgram.DoDebug("New software version found (" + newVersion.version + ") [" + newVersion.type + "], current; " + MainProgram.softwareVersion);
86+
DialogResult dialogResult = MessageBox.Show("A new version of " + MainProgram.messageBoxTitle + " is available (v" + newVersion.version + " [" + newVersion.type + "]), do you wish to install it?", "New update found | " + MainProgram.messageBoxTitle, MessageBoxButtons.YesNo);
87+
if (dialogResult == DialogResult.Yes) {
88+
MainProgram.DoDebug("User chose \"yes\" to install update");
89+
Install(newVersion.installpath);
90+
} else if (dialogResult == DialogResult.No) {
91+
MainProgram.DoDebug("User did not want to install update");
92+
}
93+
94+
if (File.Exists(Path.Combine(MainProgram.dataFolderLocation, "updated.txt"))) {
95+
File.Delete("updated.txt");
96+
}
97+
return true;
2298
}
2399
} else {
24-
MainProgram.DoDebug("Software up to date");
100+
MainProgram.DoDebug("Could not reach the webserver (both 'release' and 'beta' json files couldn't be reached)");
25101
}
26-
if (File.Exists(Path.Combine(MainProgram.dataFolderLocation, "updated.txt"))) {
27-
File.Delete("updated.txt");
102+
return false;
103+
}
104+
105+
private bool RemoteFileExists(string url) {
106+
try {
107+
//Creating the HttpWebRequest
108+
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
109+
//Setting the Request method HEAD, you can also use GET too.
110+
request.Method = "HEAD";
111+
//Getting the Web Response.
112+
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
113+
//Returns TRUE if the Status code == 200
114+
response.Close();
115+
return (response.StatusCode == HttpStatusCode.OK);
116+
} catch {
117+
//Any exception will returns false.
118+
return false;
28119
}
29120
}
30121

31-
public void Install() {
122+
public void Install(string installPath) {
32123
MainProgram.DoDebug("Installing new version...");
33-
//Create file for the updater, containing the name (and full path) of the ACC-exe which is being updated
34124
if (File.Exists(Path.Combine(MainProgram.dataFolderLocation, "updated.txt"))) {
35125
File.Delete("updated.txt");
36126
}
37-
if (File.Exists(Path.Combine(MainProgram.dataFolderLocation, "acc_location.txt"))) {
38-
File.WriteAllText(Path.Combine(MainProgram.dataFolderLocation, "acc_location.txt"), string.Empty);
39-
}
40-
using (var tw = new StreamWriter(Path.Combine(MainProgram.dataFolderLocation, "acc_location.txt"), true)) {
41-
tw.WriteLine(MainProgram.currentLocationFull);
42-
tw.Close();
127+
128+
HttpWebResponse response = null;
129+
var request = (HttpWebRequest)WebRequest.Create(installPath);
130+
request.Method = "HEAD";
131+
bool wentThrough = true;
132+
133+
try {
134+
response = (HttpWebResponse)request.GetResponse();
135+
} catch (WebException ex) {
136+
//A WebException will be thrown if the status of the response is not `200 OK`
137+
MainProgram.DoDebug("Failed to update, installation URL does not exist (" + installPath + "). Error;");
138+
MainProgram.DoDebug(ex.Message);
139+
MessageBox.Show("Couldn't find the new version online. Please try again later.", "Error | " + MainProgram.messageBoxTitle);
140+
wentThrough = false;
141+
} finally {
142+
if (response != null) {
143+
response.Close();
144+
}
43145
}
44-
string downloadLocation = Path.Combine(MainProgram.currentLocation, "ACC_installer.exe");
146+
147+
if (!wentThrough)
148+
return;
149+
150+
string downloadLocation = Path.Combine(Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), "Downloads"), "AssistantComputerControl installer.exe");
45151
using (var client = new WebClient()) {
46-
client.DownloadFile("https://gh.albe.pw/acc/installer/ACC_installer.exe", downloadLocation);
152+
client.DownloadFile(installPath, downloadLocation);
47153
}
48154
Process.Start(downloadLocation);
49155
MainProgram.Exit();

0 commit comments

Comments
 (0)