Skip to content

Commit f39144c

Browse files
authored
Merge pull request #119 from theClueless/deploymentUpdates
Auto update improvements: Updater
2 parents 6cad4bc + d74b5c8 commit f39144c

File tree

13 files changed

+151
-68
lines changed

13 files changed

+151
-68
lines changed

Wox.Core/Updater.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,23 @@
1616

1717
namespace Wox.Core
1818
{
19-
public static class Updater
19+
public class Updater
2020
{
21-
private static readonly Internationalization Translater = InternationalizationManager.Instance;
21+
public string GitHubRepository { get; }
2222

23-
public static async Task UpdateApp()
23+
public Updater(string gitHubRepository)
24+
{
25+
GitHubRepository = gitHubRepository;
26+
}
27+
28+
public async Task UpdateApp()
2429
{
2530
UpdateManager m;
2631
UpdateInfo u;
2732

2833
try
2934
{
30-
m = await GitHubUpdateManager(Constant.Repository);
35+
m = await GitHubUpdateManager(GitHubRepository);
3136
}
3237
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
3338
{
@@ -66,8 +71,8 @@ public static async Task UpdateApp()
6671
await m.ApplyReleases(u);
6772
await m.CreateUninstallerRegistryEntry();
6873

69-
var newVersionTips = Translater.GetTranslation("newVersionTips");
70-
newVersionTips = string.Format(newVersionTips, fr.Version);
74+
var newVersionTips = this.NewVersinoTips(fr.Version.ToString());
75+
7176
MessageBox.Show(newVersionTips);
7277
Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");
7378
}
@@ -90,7 +95,7 @@ private class GithubRelease
9095
}
9196

9297
/// https://github.com/Squirrel/Squirrel.Windows/blob/master/src/Squirrel/UpdateManager.Factory.cs
93-
private static async Task<UpdateManager> GitHubUpdateManager(string repository)
98+
private async Task<UpdateManager> GitHubUpdateManager(string repository)
9499
{
95100
var uri = new Uri(repository);
96101
var api = $"https://api.github.com/repos{uri.AbsolutePath}/releases";
@@ -109,7 +114,7 @@ private static async Task<UpdateManager> GitHubUpdateManager(string repository)
109114
return manager;
110115
}
111116

112-
public static string NewVersinoTips(string version)
117+
public string NewVersinoTips(string version)
113118
{
114119
var translater = InternationalizationManager.Instance;
115120
var tips = string.Format(translater.GetTranslation("newVersionTips"), version);

Wox.Infrastructure/Http/Http.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ public static class Http
1313
{
1414
private const string UserAgent = @"Mozilla/5.0 (Trident/7.0; rv:11.0) like Gecko";
1515

16+
static Http()
17+
{
18+
// need to be added so it would work on a win10 machine
19+
ServicePointManager.Expect100Continue = true;
20+
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls
21+
| SecurityProtocolType.Tls11
22+
| SecurityProtocolType.Tls12
23+
| SecurityProtocolType.Ssl3;
24+
}
25+
1626
public static HttpProxy Proxy { private get; set; }
1727
public static IWebProxy WebProxy()
1828
{

Wox.Infrastructure/Logger/Log.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ public static class Log
1111
{
1212
public const string DirectoryName = "Logs";
1313

14+
public static string CurrentLogDirectory { get; private set; }
15+
1416
static Log()
1517
{
16-
var path = Path.Combine(Constant.DataDirectory, DirectoryName, Constant.Version);
17-
if (!Directory.Exists(path))
18+
CurrentLogDirectory = Path.Combine(Constant.DataDirectory, DirectoryName, Constant.Version);
19+
if (!Directory.Exists(CurrentLogDirectory))
1820
{
19-
Directory.CreateDirectory(path);
21+
Directory.CreateDirectory(CurrentLogDirectory);
2022
}
2123

2224
var configuration = new LoggingConfiguration();
2325
var target = new FileTarget();
2426
configuration.AddTarget("file", target);
25-
target.FileName = path.Replace(@"\", "/") + "/${shortdate}.txt";
27+
target.FileName = CurrentLogDirectory.Replace(@"\", "/") + "/${shortdate}.txt";
2628
#if DEBUG
2729
var rule = new LoggingRule("*", LogLevel.Debug, target);
2830
#else

Wox.Infrastructure/Wox.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public static string DetermineDataDirectory()
2929
public static readonly string DataDirectory = DetermineDataDirectory();
3030
public static readonly string PluginsDirectory = Path.Combine(DataDirectory, Plugins);
3131
public static readonly string PreinstalledDirectory = Path.Combine(ProgramDirectory, Plugins);
32-
public const string Repository = "https://github.com/Wox-launcher/Wox";
3332
public const string Issue = "https://github.com/Wox-launcher/Wox/issues/new";
3433
public static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location.NonNull()).ProductVersion;
3534

Wox/App.config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
<?xml version="1.0"?>
22
<configuration>
33
<!--https://msdn.microsoft.com/en-us/library/dd409252(v=vs.110).aspx-->
4+
<configSections>
5+
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
6+
<section name="Wox.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
7+
</sectionGroup>
8+
</configSections>
49
<runtime>
510
<loadFromRemoteSources enabled="true"/>
611
</runtime>
12+
<applicationSettings>
13+
<Wox.Properties.Settings>
14+
<setting name="GithubRepo" serializeAs="String">
15+
<value>https://github.com/Wox-launcher/Wox</value>
16+
</setting>
17+
</Wox.Properties.Settings>
18+
</applicationSettings>
719
</configuration>

Wox/App.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public partial class App : IDisposable, ISingleInstanceApp
2525
private Settings _settings;
2626
private MainViewModel _mainVM;
2727
private SettingWindowViewModel _settingsVM;
28+
private readonly Updater _updater = new Updater(Wox.Properties.Settings.Default.GithubRepo);
2829

2930
[STAThread]
3031
public static void Main()
@@ -50,7 +51,7 @@ private void OnStartup(object sender, StartupEventArgs e)
5051

5152
ImageLoader.Initialize();
5253

53-
_settingsVM = new SettingWindowViewModel();
54+
_settingsVM = new SettingWindowViewModel(_updater);
5455
_settings = _settingsVM.Settings;
5556

5657
Alphabet.Initialize(_settings);
@@ -111,12 +112,12 @@ private void AutoUpdates()
111112
var timer = new Timer(1000 * 60 * 60 * 5);
112113
timer.Elapsed += async (s, e) =>
113114
{
114-
await Updater.UpdateApp();
115+
await _updater.UpdateApp();
115116
};
116117
timer.Start();
117118

118119
// check updates on startup
119-
await Updater.UpdateApp();
120+
await _updater.UpdateApp();
120121
}
121122
});
122123
}

Wox/Properties/Settings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Wox/Properties/Settings.settings

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<SettingsFile xmlns="uri:_settings" CurrentProfile="(Default)">
3-
<Profiles>
4-
<Profile Name="(Default)" />
5-
</Profiles>
6-
<Settings />
2+
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Wox.Properties" GeneratedClassName="Settings">
3+
<Profiles />
4+
<Settings>
5+
<Setting Name="GithubRepo" Type="System.String" Scope="Application">
6+
<Value Profile="(Default)">https://github.com/Wox-launcher/Wox</Value>
7+
</Setting>
8+
</Settings>
79
</SettingsFile>

Wox/ReportWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public ReportWindow(Exception exception)
2323

2424
private void SetException(Exception exception)
2525
{
26-
string path = Path.Combine(Constant.DataDirectory, Log.DirectoryName, Constant.Version);
26+
string path = Log.CurrentLogDirectory;
2727
var directory = new DirectoryInfo(path);
2828
var log = directory.GetFiles().OrderByDescending(f => f.LastWriteTime).First();
2929

Wox/SettingWindow.xaml.cs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -260,53 +260,16 @@ private void OnPluginDirecotyClick(object sender, MouseButtonEventArgs e)
260260
#region Proxy
261261

262262
private void OnTestProxyClick(object sender, RoutedEventArgs e)
263-
{
264-
if (string.IsNullOrEmpty(_settings.Proxy.Server))
265-
{
266-
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
267-
return;
268-
}
269-
if (_settings.Proxy.Port <= 0)
270-
{
271-
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
272-
return;
273-
}
274-
275-
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Infrastructure.Constant.Repository);
276-
if (string.IsNullOrEmpty(_settings.Proxy.UserName) || string.IsNullOrEmpty(_settings.Proxy.Password))
277-
{
278-
request.Proxy = new WebProxy(_settings.Proxy.Server, _settings.Proxy.Port);
279-
}
280-
else
281-
{
282-
request.Proxy = new WebProxy(_settings.Proxy.Server, _settings.Proxy.Port)
283-
{
284-
Credentials = new NetworkCredential(_settings.Proxy.UserName, _settings.Proxy.Password)
285-
};
286-
}
287-
try
288-
{
289-
var response = (HttpWebResponse)request.GetResponse();
290-
if (response.StatusCode == HttpStatusCode.OK)
291-
{
292-
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyIsCorrect"));
293-
}
294-
else
295-
{
296-
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyConnectFailed"));
297-
}
298-
}
299-
catch
300-
{
301-
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyConnectFailed"));
302-
}
263+
{ // TODO: change to command
264+
var msg = _viewModel.TestProxy();
265+
MessageBox.Show(msg); // TODO: add message box service
303266
}
304267

305268
#endregion
306269

307270
private async void OnCheckUpdates(object sender, RoutedEventArgs e)
308271
{
309-
await Updater.UpdateApp();
272+
_viewModel.UpdateApp(); // TODO: change to command
310273
}
311274

312275
private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)

0 commit comments

Comments
 (0)