Improve the update progress.

This commit is contained in:
qianlifeng
2015-01-21 23:00:56 +08:00
parent 563370f10b
commit 00953850b3
22 changed files with 103 additions and 278 deletions

View File

@@ -1,18 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Settings> <Settings>
<SCOTT-PC> <BaseURL>http://127.0.0.1:8888</BaseURL>
<IgnoreVsHosting>True</IgnoreVsHosting> <IgnoreVsHosting>True</IgnoreVsHosting>
<CompareSize>False</CompareSize> <CompareSize>False</CompareSize>
<CleanUp>True</CleanUp> <CleanUp>True</CleanUp>
<IgnoreDebugSymbols>True</IgnoreDebugSymbols> <IgnoreDebugSymbols>False</IgnoreDebugSymbols>
<IgnoreFiles>&lt;?xml version="1.0" encoding="utf-16"?&gt; <IgnoreFiles>&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /&gt;</IgnoreFiles> &lt;ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" /&gt;</IgnoreFiles>
<CopyFiles>True</CopyFiles> <CopyFiles>True</CopyFiles>
<CompareVersion>True</CompareVersion> <CompareVersion>False</CompareVersion>
<OutputFolder>E:\github\Wox\Output\Debug</OutputFolder> <OutputFolder>..\..\Output\Release</OutputFolder>
<CompareHash>True</CompareHash> <CompareHash>True</CompareHash>
<CompareDate>False</CompareDate> <CompareDate>False</CompareDate>
<FeedXML>E:\github\Wox\Output\Update\Update.xml</FeedXML> <FeedXML>..\..\Output\Update\Update.xml</FeedXML>
</SCOTT-PC>
<BaseURL>http://127.0.0.1:8888</BaseURL>
</Settings> </Settings>

Binary file not shown.

View File

@@ -39,7 +39,7 @@ namespace Wox.Core.UI
foreach (var pluginI18n in pluginI18ns) foreach (var pluginI18n in pluginI18ns)
{ {
string languageFile = InternationalizationManager.Internationalization.GetLanguageFile( string languageFile = InternationalizationManager.Instance.GetLanguageFile(
((IPluginI18n)Activator.CreateInstance(pluginI18n)).GetLanguagesFolder()); ((IPluginI18n)Activator.CreateInstance(pluginI18n)).GetLanguagesFolder());
if (!string.IsNullOrEmpty(languageFile)) if (!string.IsNullOrEmpty(languageFile))
{ {

View File

@@ -6,6 +6,8 @@ using System.Windows.Threading;
using NAppUpdate.Framework; using NAppUpdate.Framework;
using NAppUpdate.Framework.Common; using NAppUpdate.Framework.Common;
using NAppUpdate.Framework.Sources; using NAppUpdate.Framework.Sources;
using Wox.Core.i18n;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Logger; using Wox.Infrastructure.Logger;
namespace Wox.Core.Updater namespace Wox.Core.Updater
@@ -31,11 +33,14 @@ namespace Wox.Core.Updater
UpdateManager.Instance.UpdateSource = GetUpdateSource(); UpdateManager.Instance.UpdateSource = GetUpdateSource();
} }
public bool IsUpdateAvailable()
{
return UpdateManager.Instance.UpdatesAvailable > 0;
}
public void CheckUpdate() public void CheckUpdate()
{ {
// Get a local pointer to the UpdateManager instance
UpdateManager updManager = UpdateManager.Instance; UpdateManager updManager = UpdateManager.Instance;
updManager.BeginCheckForUpdates(asyncResult => updManager.BeginCheckForUpdates(asyncResult =>
{ {
if (asyncResult.IsCompleted) if (asyncResult.IsCompleted)
@@ -43,9 +48,9 @@ namespace Wox.Core.Updater
// still need to check for caught exceptions if any and rethrow // still need to check for caught exceptions if any and rethrow
try try
{ {
((UpdateProcessAsyncResult) asyncResult).EndInvoke(); ((UpdateProcessAsyncResult)asyncResult).EndInvoke();
} }
catch(System.Exception e) catch (System.Exception e)
{ {
Log.Error(e); Log.Error(e);
updManager.CleanUp(); updManager.CleanUp();
@@ -55,7 +60,6 @@ namespace Wox.Core.Updater
// No updates were found, or an error has occured. We might want to check that... // No updates were found, or an error has occured. We might want to check that...
if (updManager.UpdatesAvailable == 0) if (updManager.UpdatesAvailable == 0)
{ {
MessageBox.Show("All is up to date!");
return; return;
} }
} }
@@ -63,53 +67,44 @@ namespace Wox.Core.Updater
updManager.BeginPrepareUpdates(result => updManager.BeginPrepareUpdates(result =>
{ {
((UpdateProcessAsyncResult)result).EndInvoke(); ((UpdateProcessAsyncResult)result).EndInvoke();
string updateReady = InternationalizationManager.Instance.GetTranslation("update_wox_update_ready");
string updateInstall = InternationalizationManager.Instance.GetTranslation("update_wox_update_install");
updateInstall = string.Format(updateInstall, updManager.UpdatesAvailable);
DialogResult dr = MessageBox.Show(updateInstall, updateReady, MessageBoxButtons.YesNo);
// ApplyUpdates is a synchronous method by design. Make sure to save all user work before calling if (dr == DialogResult.Yes)
// it as it might restart your application
// get out of the way so the console window isn't obstructed
try
{ {
updManager.ApplyUpdates(true,false,true);
}
catch
{
// this.WindowState = WindowState.Normal;
MessageBox.Show(
"An error occurred while trying to install software updates");
}
updManager.CleanUp(); // ApplyUpdates is a synchronous method by design. Make sure to save all user work before calling
// it as it might restart your application
// get out of the way so the console window isn't obstructed
try
{
updManager.ApplyUpdates(true, UserSettingStorage.Instance.EnableUpdateLog, false);
}
catch (System.Exception e)
{
string updateError =
InternationalizationManager.Instance.GetTranslation("update_wox_update_error");
Log.Error(e);
MessageBox.Show(updateError);
}
updManager.CleanUp();
}
else
{
updManager.CleanUp();
}
}, null); }, null);
}, null); }, null);
} }
public void Reinstall()
{
UpdateManager.Instance.ReinstateIfRestarted();
}
private void OnPrepareUpdatesCompleted(bool obj)
{
UpdateManager updManager = UpdateManager.Instance;
DialogResult dr = MessageBox.Show(
"Updates are ready to install. Do you wish to install them now?",
"Software updates ready",
MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
// This is a synchronous method by design, make sure to save all user work before calling
// it as it might restart your application
updManager.ApplyUpdates(true,true,true);
}
}
private IUpdateSource GetUpdateSource() private IUpdateSource GetUpdateSource()
{ {
// Normally this would be a web based source. // Normally this would be a web based source.
// But for the demo app, we prepare an in-memory source. // But for the demo app, we prepare an in-memory source.
var source = new NAppUpdate.Framework.Sources.SimpleWebSource("http://127.0.0.1:8888/Update.xml"); var source = new SimpleWebSource("http://127.0.0.1:8888/Update.xml");
return source; return source;
} }
} }

View File

@@ -14,6 +14,9 @@ namespace Wox.Core.UserSettings
[JsonProperty] [JsonProperty]
public bool DontPromptUpdateMsg { get; set; } public bool DontPromptUpdateMsg { get; set; }
[JsonProperty]
public bool EnableUpdateLog { get; set; }
[JsonProperty] [JsonProperty]
public string Hotkey { get; set; } public string Hotkey { get; set; }

View File

@@ -14,7 +14,7 @@ namespace Wox.Core.i18n
private static Internationalization instance; private static Internationalization instance;
private static object syncObject = new object(); private static object syncObject = new object();
public static Internationalization Internationalization public static Internationalization Instance
{ {
get get
{ {

View File

@@ -45,7 +45,7 @@ namespace Wox.CrashReporter
private void btnSend_Click(object sender, RoutedEventArgs e) private void btnSend_Click(object sender, RoutedEventArgs e)
{ {
string sendingMsg = InternationalizationManager.Internationalization.GetTranslation("reportWindow_sending"); string sendingMsg = InternationalizationManager.Instance.GetTranslation("reportWindow_sending");
tbSendReport.Content = sendingMsg; tbSendReport.Content = sendingMsg;
btnSend.IsEnabled = false; btnSend.IsEnabled = false;
ThreadPool.QueueUserWorkItem(o => SendReport()); ThreadPool.QueueUserWorkItem(o => SendReport());
@@ -57,11 +57,11 @@ namespace Wox.CrashReporter
string response = HttpRequest.Post(APIServer.ErrorReportURL, error, HttpProxy.Instance); string response = HttpRequest.Post(APIServer.ErrorReportURL, error, HttpProxy.Instance);
if (response.ToLower() == "ok") if (response.ToLower() == "ok")
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("reportWindow_report_succeed")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("reportWindow_report_succeed"));
} }
else else
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("reportWindow_report_failed")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("reportWindow_report_failed"));
} }
Dispatcher.Invoke(new Action(Close)); Dispatcher.Invoke(new Action(Close));
} }

View File

@@ -29,7 +29,7 @@ namespace Wox
PluginPair plugin = PluginManager.GetPlugin(pluginId); PluginPair plugin = PluginManager.GetPlugin(pluginId);
if (plugin == null) if (plugin == null)
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("cannotFindSpecifiedPlugin")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("cannotFindSpecifiedPlugin"));
Close(); Close();
return; return;
} }
@@ -52,14 +52,14 @@ namespace Wox
{ {
if (string.IsNullOrEmpty(tbAction.Text)) if (string.IsNullOrEmpty(tbAction.Text))
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("newActionKeywordCannotBeEmpty")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("newActionKeywordCannotBeEmpty"));
return; return;
} }
//check new action keyword didn't used by other plugin //check new action keyword didn't used by other plugin
if (PluginManager.AllPlugins.Exists(o => o.Metadata.ActionKeyword == tbAction.Text.Trim())) if (PluginManager.AllPlugins.Exists(o => o.Metadata.ActionKeyword == tbAction.Text.Trim()))
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("newActionKeywordHasBeenAssigned")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("newActionKeywordHasBeenAssigned"));
return; return;
} }
@@ -81,7 +81,7 @@ namespace Wox
customizedPluginConfig.Actionword = tbAction.Text.Trim(); customizedPluginConfig.Actionword = tbAction.Text.Trim();
} }
UserSettingStorage.Instance.Save(); UserSettingStorage.Instance.Save();
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("succeed")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
Close(); Close();
} }
} }

View File

@@ -29,7 +29,7 @@ namespace Wox
{ {
if (!ctlHotkey.CurrentHotkeyAvailable) if (!ctlHotkey.CurrentHotkeyAvailable)
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("hotkeyIsNotUnavailable")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("hotkeyIsNotUnavailable"));
return; return;
} }
@@ -49,13 +49,13 @@ namespace Wox
settingWidow.MainWindow.ChangeQuery(pluginHotkey.ActionKeyword); settingWidow.MainWindow.ChangeQuery(pluginHotkey.ActionKeyword);
settingWidow.MainWindow.ShowApp(); settingWidow.MainWindow.ShowApp();
}); });
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("succeed")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
} }
else else
{ {
if (updateCustomHotkey.Hotkey != ctlHotkey.CurrentHotkey.ToString() && !ctlHotkey.CurrentHotkeyAvailable) if (updateCustomHotkey.Hotkey != ctlHotkey.CurrentHotkey.ToString() && !ctlHotkey.CurrentHotkeyAvailable)
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("hotkeyIsNotUnavailable")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("hotkeyIsNotUnavailable"));
return; return;
} }
var oldHotkey = updateCustomHotkey.Hotkey; var oldHotkey = updateCustomHotkey.Hotkey;
@@ -68,7 +68,7 @@ namespace Wox
settingWidow.MainWindow.ShowApp(); settingWidow.MainWindow.ShowApp();
settingWidow.MainWindow.ChangeQuery(updateCustomHotkey.ActionKeyword); settingWidow.MainWindow.ChangeQuery(updateCustomHotkey.ActionKeyword);
}); });
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("succeed")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("succeed"));
} }
UserSettingStorage.Instance.Save(); UserSettingStorage.Instance.Save();
@@ -81,7 +81,7 @@ namespace Wox
updateCustomHotkey = UserSettingStorage.Instance.CustomPluginHotkeys.FirstOrDefault(o => o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey); updateCustomHotkey = UserSettingStorage.Instance.CustomPluginHotkeys.FirstOrDefault(o => o.ActionKeyword == item.ActionKeyword && o.Hotkey == item.Hotkey);
if (updateCustomHotkey == null) if (updateCustomHotkey == null)
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("invalidPluginHotkey")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPluginHotkey"));
Close(); Close();
return; return;
} }
@@ -89,7 +89,7 @@ namespace Wox
tbAction.Text = updateCustomHotkey.ActionKeyword; tbAction.Text = updateCustomHotkey.ActionKeyword;
ctlHotkey.SetHotkey(updateCustomHotkey.Hotkey, false); ctlHotkey.SetHotkey(updateCustomHotkey.Hotkey, false);
update = true; update = true;
lblAdd.Text = InternationalizationManager.Internationalization.GetTranslation("update"); lblAdd.Text = InternationalizationManager.Instance.GetTranslation("update");
} }
private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e) private void BtnTestActionKeyword_OnClick(object sender, RoutedEventArgs e)

View File

@@ -99,12 +99,12 @@ namespace Wox
if (!CurrentHotkeyAvailable) if (!CurrentHotkeyAvailable)
{ {
tbMsg.Foreground = new SolidColorBrush(Colors.Red); tbMsg.Foreground = new SolidColorBrush(Colors.Red);
tbMsg.Text = InternationalizationManager.Internationalization.GetTranslation("hotkeyUnavailable"); tbMsg.Text = InternationalizationManager.Instance.GetTranslation("hotkeyUnavailable");
} }
else else
{ {
tbMsg.Foreground = new SolidColorBrush(Colors.Green); tbMsg.Foreground = new SolidColorBrush(Colors.Green);
tbMsg.Text = InternationalizationManager.Internationalization.GetTranslation("succeed"); tbMsg.Text = InternationalizationManager.Instance.GetTranslation("succeed");
} }
OnOnHotkeyChanged(); OnOnHotkeyChanged();
} }

View File

@@ -98,4 +98,9 @@
<system:String x:Key="reportWindow_report_failed">Report failed</system:String> <system:String x:Key="reportWindow_report_failed">Report failed</system:String>
<system:String x:Key="reportWindow_wox_got_an_error">Wox got an error</system:String> <system:String x:Key="reportWindow_wox_got_an_error">Wox got an error</system:String>
<!--update-->
<system:String x:Key="update_wox_update_ready">Wox updates available</system:String>
<system:String x:Key="update_wox_update_install">Wox updates are ready to install. {0} files will be added and replaced, this operation may restart Wox. Do you wish to install them now?</system:String>
<system:String x:Key="update_wox_update_error">An error occurred while trying to install software updates</system:String>
</ResourceDictionary> </ResourceDictionary>

View File

@@ -97,4 +97,10 @@
<system:String x:Key="reportWindow_report_succeed">发送成功</system:String> <system:String x:Key="reportWindow_report_succeed">发送成功</system:String>
<system:String x:Key="reportWindow_report_failed">发送失败</system:String> <system:String x:Key="reportWindow_report_failed">发送失败</system:String>
<system:String x:Key="reportWindow_wox_got_an_error">Wox出错啦</system:String> <system:String x:Key="reportWindow_wox_got_an_error">Wox出错啦</system:String>
<!--更新-->
<system:String x:Key="update_wox_update_ready">Wox更新</system:String>
<system:String x:Key="update_wox_update_install">Wox更新啦{0}个文件会被添加和替换并且在此过程中可能会重启Wox。你确定需要更新吗</system:String>
<system:String x:Key="update_wox_update_error">更新Wox出错</system:String>
</ResourceDictionary> </ResourceDictionary>

View File

@@ -98,4 +98,9 @@
<system:String x:Key="reportWindow_report_failed">發送失敗</system:String> <system:String x:Key="reportWindow_report_failed">發送失敗</system:String>
<system:String x:Key="reportWindow_wox_got_an_error">Wox出錯啦</system:String> <system:String x:Key="reportWindow_wox_got_an_error">Wox出錯啦</system:String>
<!--更新-->
<system:String x:Key="update_wox_update_ready">Wox更新</system:String>
<system:String x:Key="update_wox_update_install">Wox更新啦{0}個文件會被添加和替換並且在此過程中可能會重啟Wox。你確定需要更新嗎</system:String>
<system:String x:Key="update_wox_update_error">更新Wox出錯</system:String>
</ResourceDictionary> </ResourceDictionary>

View File

@@ -24,7 +24,6 @@ using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Hotkey;
using Wox.Plugin; using Wox.Plugin;
using Wox.Storage; using Wox.Storage;
using Wox.Update;
using Brushes = System.Windows.Media.Brushes; using Brushes = System.Windows.Media.Brushes;
using Color = System.Windows.Media.Color; using Color = System.Windows.Media.Color;
using ContextMenu = System.Windows.Forms.ContextMenu; using ContextMenu = System.Windows.Forms.ContextMenu;
@@ -124,7 +123,7 @@ namespace Wox
public string GetTranslation(string key) public string GetTranslation(string key)
{ {
return InternationalizationManager.Internationalization.GetTranslation(key); return InternationalizationManager.Instance.GetTranslation(key);
} }
public List<PluginPair> GetAllPlugins() public List<PluginPair> GetAllPlugins()
@@ -175,7 +174,7 @@ namespace Wox
pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent; pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent;
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme); ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
InternationalizationManager.Internationalization.ChangeLanguage(UserSettingStorage.Instance.Language); InternationalizationManager.Instance.ChangeLanguage(UserSettingStorage.Instance.Language);
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey); SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
SetCustomPluginHotkey(); SetCustomPluginHotkey();
@@ -193,7 +192,6 @@ namespace Wox
Thread.Sleep(50); Thread.Sleep(50);
PreLoadImages(); PreLoadImages();
}); });
CheckUpdate();
} }
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
@@ -215,22 +213,6 @@ namespace Wox
ShowContextMenu(result); ShowContextMenu(result);
} }
void CheckUpdate()
{
ThreadPool.QueueUserWorkItem(o =>
{
Release release = new UpdateChecker().CheckUpgrade();
if (release != null && !UserSettingStorage.Instance.DontPromptUpdateMsg)
{
Dispatcher.Invoke(new Action(() =>
{
NewVersionWindow newVersinoWindow = new NewVersionWindow();
newVersinoWindow.Show();
}));
}
});
}
void MainWindow_Closing(object sender, CancelEventArgs e) void MainWindow_Closing(object sender, CancelEventArgs e)
{ {
UserSettingStorage.Instance.WindowLeft = Left; UserSettingStorage.Instance.WindowLeft = Left;
@@ -278,7 +260,7 @@ namespace Wox
} }
catch (Exception) catch (Exception)
{ {
string errorMsg = string.Format(InternationalizationManager.Internationalization.GetTranslation("registerHotkeyFailed"), hotkeyStr); string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
MessageBox.Show(errorMsg); MessageBox.Show(errorMsg);
} }
} }
@@ -673,7 +655,7 @@ namespace Wox
} }
catch (Exception ex) catch (Exception ex)
{ {
string errorMsg = string.Format(InternationalizationManager.Internationalization.GetTranslation("couldnotStartCmd"), cmd); string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("couldnotStartCmd"), cmd);
ShowMsg(errorMsg, ex.Message, null); ShowMsg(errorMsg, ex.Message, null);
} }
return false; return false;
@@ -691,7 +673,7 @@ namespace Wox
} }
else else
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("invalidWoxPluginFileFormat")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidWoxPluginFileFormat"));
} }
} }
} }

View File

@@ -318,7 +318,6 @@
<TextBlock Grid.Column="0" Grid.Row="1" Margin="6" Text="{DynamicResource version}"></TextBlock> <TextBlock Grid.Column="0" Grid.Row="1" Margin="6" Text="{DynamicResource version}"></TextBlock>
<StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal"> <StackPanel Grid.Column="1" Grid.Row="1" Orientation="Horizontal">
<TextBlock Margin="6" HorizontalAlignment="Left" x:Name="tbVersion" Text="1.0.0"></TextBlock> <TextBlock Margin="6" HorizontalAlignment="Left" x:Name="tbVersion" Text="1.0.0"></TextBlock>
<TextBlock Margin="6" HorizontalAlignment="Left" Cursor="Hand" MouseUp="tbNewVersionAvailable_MouseUp" x:Name="tbNewVersionAvailable" Foreground="Blue" Text="1.1.0 Available"></TextBlock>
</StackPanel> </StackPanel>
</Grid> </Grid>
</TabItem> </TabItem>

View File

@@ -13,7 +13,6 @@ using System.Windows.Media.Imaging;
using Wox.Core.Plugin; using Wox.Core.Plugin;
using Wox.Plugin; using Wox.Plugin;
using Wox.Helper; using Wox.Helper;
using Wox.Update;
using Application = System.Windows.Forms.Application; using Application = System.Windows.Forms.Application;
using File = System.IO.File; using File = System.IO.File;
using MessageBox = System.Windows.MessageBox; using MessageBox = System.Windows.MessageBox;
@@ -218,15 +217,6 @@ namespace Wox
#region About #region About
tbVersion.Text = ConfigurationManager.AppSettings["version"]; tbVersion.Text = ConfigurationManager.AppSettings["version"];
Release newRelease = new UpdateChecker().CheckUpgrade();
if (newRelease == null)
{
tbNewVersionAvailable.Visibility = Visibility.Collapsed;
}
else
{
tbNewVersionAvailable.Text = newRelease.version + " available";
}
#endregion #endregion
@@ -235,7 +225,7 @@ namespace Wox
private void LoadLanguages() private void LoadLanguages()
{ {
cbLanguages.ItemsSource = InternationalizationManager.Internationalization.LoadAvailableLanguages(); cbLanguages.ItemsSource = InternationalizationManager.Instance.LoadAvailableLanguages();
cbLanguages.DisplayMemberPath = "Display"; cbLanguages.DisplayMemberPath = "Display";
cbLanguages.SelectedValuePath = "LanguageCode"; cbLanguages.SelectedValuePath = "LanguageCode";
cbLanguages.SelectedValue = UserSettingStorage.Instance.Language; cbLanguages.SelectedValue = UserSettingStorage.Instance.Language;
@@ -244,7 +234,7 @@ namespace Wox
void cbLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e) void cbLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
InternationalizationManager.Internationalization.ChangeLanguage(cbLanguages.SelectedItem as Language); InternationalizationManager.Instance.ChangeLanguage(cbLanguages.SelectedItem as Language);
} }
private void EnableProxy() private void EnableProxy()
@@ -329,12 +319,12 @@ namespace Wox
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey; CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
if (item == null) if (item == null)
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("pleaseSelectAnItem")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
return; return;
} }
string deleteWarning = string.Format(InternationalizationManager.Internationalization.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey); string deleteWarning = string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey);
if (MessageBox.Show(deleteWarning, InternationalizationManager.Internationalization.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes) if (MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{ {
UserSettingStorage.Instance.CustomPluginHotkeys.Remove(item); UserSettingStorage.Instance.CustomPluginHotkeys.Remove(item);
lvCustomHotkey.Items.Refresh(); lvCustomHotkey.Items.Refresh();
@@ -354,7 +344,7 @@ namespace Wox
} }
else else
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("pleaseSelectAnItem")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
} }
} }
@@ -488,7 +478,7 @@ namespace Wox
pluginTitle.Text = pair.Metadata.Name; pluginTitle.Text = pair.Metadata.Name;
pluginTitle.Cursor = Cursors.Hand; pluginTitle.Cursor = Cursors.Hand;
pluginActionKeyword.Text = pair.Metadata.ActionKeyword; pluginActionKeyword.Text = pair.Metadata.ActionKeyword;
pluginAuthor.Text = InternationalizationManager.Internationalization.GetTranslation("author") + ": " + pair.Metadata.Author; pluginAuthor.Text = InternationalizationManager.Instance.GetTranslation("author") + ": " + pair.Metadata.Author;
pluginSubTitle.Text = pair.Metadata.Description; pluginSubTitle.Text = pair.Metadata.Description;
pluginId = pair.Metadata.ID; pluginId = pair.Metadata.ID;
pluginIcon.Source = ImageLoader.ImageLoader.Load(pair.Metadata.FullIcoPath); pluginIcon.Source = ImageLoader.ImageLoader.Load(pair.Metadata.FullIcoPath);
@@ -627,17 +617,17 @@ namespace Wox
{ {
if (string.IsNullOrEmpty(tbProxyServer.Text)) if (string.IsNullOrEmpty(tbProxyServer.Text))
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("serverCantBeEmpty")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
return; return;
} }
if (string.IsNullOrEmpty(tbProxyPort.Text)) if (string.IsNullOrEmpty(tbProxyPort.Text))
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("portCantBeEmpty")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
return; return;
} }
if (!int.TryParse(tbProxyPort.Text, out port)) if (!int.TryParse(tbProxyPort.Text, out port))
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("invalidPortFormat")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPortFormat"));
return; return;
} }
} }
@@ -648,25 +638,25 @@ namespace Wox
UserSettingStorage.Instance.ProxyPassword = tbProxyPassword.Password; UserSettingStorage.Instance.ProxyPassword = tbProxyPassword.Password;
UserSettingStorage.Instance.Save(); UserSettingStorage.Instance.Save();
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("saveProxySuccessfully")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("saveProxySuccessfully"));
} }
private void btnTestProxy_Click(object sender, RoutedEventArgs e) private void btnTestProxy_Click(object sender, RoutedEventArgs e)
{ {
if (string.IsNullOrEmpty(tbProxyServer.Text)) if (string.IsNullOrEmpty(tbProxyServer.Text))
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("serverCantBeEmpty")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
return; return;
} }
if (string.IsNullOrEmpty(tbProxyPort.Text)) if (string.IsNullOrEmpty(tbProxyPort.Text))
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("portCantBeEmpty")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
return; return;
} }
int port; int port;
if (!int.TryParse(tbProxyPort.Text, out port)) if (!int.TryParse(tbProxyPort.Text, out port))
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("invalidPortFormat")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPortFormat"));
return; return;
} }
@@ -687,16 +677,16 @@ namespace Wox
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK) if (response.StatusCode == HttpStatusCode.OK)
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("proxyIsCorrect")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyIsCorrect"));
} }
else else
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("proxyConnectFailed")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyConnectFailed"));
} }
} }
catch catch
{ {
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("proxyConnectFailed")); MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyConnectFailed"));
} }
} }
@@ -704,14 +694,5 @@ namespace Wox
{ {
Process.Start("http://www.getwox.com"); Process.Start("http://www.getwox.com");
} }
private void tbNewVersionAvailable_MouseUp(object sender, MouseButtonEventArgs e)
{
Release newRelease = new UpdateChecker().CheckUpgrade();
if (newRelease != null)
{
Process.Start("http://www.getwox.com/release/version/" + newRelease.version);
}
}
} }
} }

View File

@@ -1,23 +0,0 @@
<Window x:Class="Wox.Update.NewVersionWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Icon="..\Images\app.png"
Topmost="True"
WindowStartupLocation="CenterScreen"
Title="New Version Found" Height="120" Width="300">
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Margin="6" HorizontalAlignment="Left" Text="Current Version"></TextBlock>
<TextBlock Grid.Column="1" Grid.Row="0" Margin="6" HorizontalAlignment="Left" x:Name="tbCurrentVersion" Text="1.0.0"></TextBlock>
<TextBlock Grid.Column="0" Grid.Row="1" Margin="6" HorizontalAlignment="Left" Text="New Version"></TextBlock>
<TextBlock Grid.Column="1" Grid.Row="1" Margin="6" HorizontalAlignment="Left" x:Name="tbNewVersion" Foreground="Blue" Cursor="Hand" MouseUp="tbNewVersion_MouseUp" Text="1.0.0"></TextBlock>
</Grid>
</Window>

View File

@@ -1,46 +0,0 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wox.Core.Version;
namespace Wox.Update
{
public partial class NewVersionWindow : Window
{
public NewVersionWindow()
{
InitializeComponent();
tbCurrentVersion.Text = VersionManager.Instance.CurrentVersion.ToString();
Release newRelease = new UpdateChecker().CheckUpgrade();
if (newRelease == null)
{
tbNewVersion.Visibility = Visibility.Collapsed;
}
else
{
tbNewVersion.Text = newRelease.version;
}
}
private void tbNewVersion_MouseUp(object sender, MouseButtonEventArgs e)
{
Release newRelease = new UpdateChecker().CheckUpgrade();
if (newRelease != null)
{
Process.Start("http://www.getwox.com/release/version/" + newRelease.version);
}
}
}
}

View File

@@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.Update
{
public class Release
{
public string version { get; set; }
public string download_link { get; set; }
public string download_link1 { get; set; }
public string download_link2 { get; set; }
public string description { get; set; }
}
}

View File

@@ -1,55 +0,0 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using Newtonsoft.Json;
using Wox.Core;
using Wox.Core.UserSettings;
using Wox.Core.Version;
using Wox.Helper;
using Wox.Infrastructure;
using Wox.Infrastructure.Http;
namespace Wox.Update
{
public class UpdateChecker
{
private static Release newRelease;
private static bool checkedUpdate = false;
/// <summary>
/// If new release is available, then return the new release
/// otherwise, return null
/// </summary>
/// <returns></returns>
public Release CheckUpgrade(bool forceCheck = false)
{
if (checkedUpdate && !forceCheck) return newRelease;
string json = HttpRequest.Get(APIServer.LastestReleaseURL,HttpProxy.Instance);
if (string.IsNullOrEmpty(json)) return null;
try
{
newRelease = JsonConvert.DeserializeObject<Release>(json);
if (!IsNewerThanCurrent(newRelease))
{
newRelease = null;
}
checkedUpdate = true;
}
catch{}
return newRelease;
}
private bool IsNewerThanCurrent(Release release)
{
if (release == null) return false;
return new SemanticVersion(release.version) > VersionManager.Instance.CurrentVersion;
}
}
}

View File

@@ -113,11 +113,6 @@
<Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" /> <Compile Include="Converters\StringNullOrEmptyToVisibilityConverter.cs" />
<Compile Include="ImageLoader\ImageCacheStroage.cs" /> <Compile Include="ImageLoader\ImageCacheStroage.cs" />
<Compile Include="Storage\UserSelectedRecordStorage.cs" /> <Compile Include="Storage\UserSelectedRecordStorage.cs" />
<Compile Include="Update\NewVersionWindow.xaml.cs">
<DependentUpon>NewVersionWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Update\Release.cs" />
<Compile Include="Update\UpdateChecker.cs" />
<Page Include="App.xaml"> <Page Include="App.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
@@ -235,10 +230,6 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
<Page Include="Update\NewVersionWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">

View File

@@ -15,7 +15,7 @@ build:
after_test: after_test:
- ps: .\deploy\nuget\pack.ps1 - ps: .\deploy\nuget\pack.ps1
- ps: .\deploy\Installer\pack.ps1 - cmd: .\deploy\NAppUpdate\build.bat
deploy: deploy:
provider: NuGet provider: NuGet
@@ -32,5 +32,5 @@ artifacts:
- path: '*.nupkg' - path: '*.nupkg'
name: nugetpackage name: nugetpackage
- path: Output\Wox-setup.exe - path: Output\Update
name: setup name: update-binary