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

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

View File

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

View File

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

View File

@@ -98,4 +98,9 @@
<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>
<!--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>

View File

@@ -97,4 +97,10 @@
<system:String x:Key="reportWindow_report_succeed">发送成功</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="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>

View File

@@ -98,4 +98,9 @@
<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="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>

View File

@@ -24,7 +24,6 @@ using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey;
using Wox.Plugin;
using Wox.Storage;
using Wox.Update;
using Brushes = System.Windows.Media.Brushes;
using Color = System.Windows.Media.Color;
using ContextMenu = System.Windows.Forms.ContextMenu;
@@ -124,7 +123,7 @@ namespace Wox
public string GetTranslation(string key)
{
return InternationalizationManager.Internationalization.GetTranslation(key);
return InternationalizationManager.Instance.GetTranslation(key);
}
public List<PluginPair> GetAllPlugins()
@@ -175,7 +174,7 @@ namespace Wox
pnlResult.RightMouseClickEvent += pnlResult_RightMouseClickEvent;
ThemeManager.Theme.ChangeTheme(UserSettingStorage.Instance.Theme);
InternationalizationManager.Internationalization.ChangeLanguage(UserSettingStorage.Instance.Language);
InternationalizationManager.Instance.ChangeLanguage(UserSettingStorage.Instance.Language);
SetHotkey(UserSettingStorage.Instance.Hotkey, OnHotkey);
SetCustomPluginHotkey();
@@ -193,7 +192,6 @@ namespace Wox
Thread.Sleep(50);
PreLoadImages();
});
CheckUpdate();
}
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state)
@@ -215,22 +213,6 @@ namespace Wox
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)
{
UserSettingStorage.Instance.WindowLeft = Left;
@@ -278,7 +260,7 @@ namespace Wox
}
catch (Exception)
{
string errorMsg = string.Format(InternationalizationManager.Internationalization.GetTranslation("registerHotkeyFailed"), hotkeyStr);
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
MessageBox.Show(errorMsg);
}
}
@@ -673,7 +655,7 @@ namespace Wox
}
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);
}
return false;
@@ -691,7 +673,7 @@ namespace Wox
}
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>
<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" Cursor="Hand" MouseUp="tbNewVersionAvailable_MouseUp" x:Name="tbNewVersionAvailable" Foreground="Blue" Text="1.1.0 Available"></TextBlock>
</StackPanel>
</Grid>
</TabItem>

View File

@@ -13,7 +13,6 @@ using System.Windows.Media.Imaging;
using Wox.Core.Plugin;
using Wox.Plugin;
using Wox.Helper;
using Wox.Update;
using Application = System.Windows.Forms.Application;
using File = System.IO.File;
using MessageBox = System.Windows.MessageBox;
@@ -218,15 +217,6 @@ namespace Wox
#region About
tbVersion.Text = ConfigurationManager.AppSettings["version"];
Release newRelease = new UpdateChecker().CheckUpgrade();
if (newRelease == null)
{
tbNewVersionAvailable.Visibility = Visibility.Collapsed;
}
else
{
tbNewVersionAvailable.Text = newRelease.version + " available";
}
#endregion
@@ -235,7 +225,7 @@ namespace Wox
private void LoadLanguages()
{
cbLanguages.ItemsSource = InternationalizationManager.Internationalization.LoadAvailableLanguages();
cbLanguages.ItemsSource = InternationalizationManager.Instance.LoadAvailableLanguages();
cbLanguages.DisplayMemberPath = "Display";
cbLanguages.SelectedValuePath = "LanguageCode";
cbLanguages.SelectedValue = UserSettingStorage.Instance.Language;
@@ -244,7 +234,7 @@ namespace Wox
void cbLanguages_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
InternationalizationManager.Internationalization.ChangeLanguage(cbLanguages.SelectedItem as Language);
InternationalizationManager.Instance.ChangeLanguage(cbLanguages.SelectedItem as Language);
}
private void EnableProxy()
@@ -329,12 +319,12 @@ namespace Wox
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
if (item == null)
{
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("pleaseSelectAnItem"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("pleaseSelectAnItem"));
return;
}
string deleteWarning = string.Format(InternationalizationManager.Internationalization.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey);
if (MessageBox.Show(deleteWarning, InternationalizationManager.Internationalization.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
string deleteWarning = string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey);
if (MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
UserSettingStorage.Instance.CustomPluginHotkeys.Remove(item);
lvCustomHotkey.Items.Refresh();
@@ -354,7 +344,7 @@ namespace Wox
}
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.Cursor = Cursors.Hand;
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;
pluginId = pair.Metadata.ID;
pluginIcon.Source = ImageLoader.ImageLoader.Load(pair.Metadata.FullIcoPath);
@@ -627,17 +617,17 @@ namespace Wox
{
if (string.IsNullOrEmpty(tbProxyServer.Text))
{
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("serverCantBeEmpty"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
return;
}
if (string.IsNullOrEmpty(tbProxyPort.Text))
{
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("portCantBeEmpty"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
return;
}
if (!int.TryParse(tbProxyPort.Text, out port))
{
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("invalidPortFormat"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPortFormat"));
return;
}
}
@@ -648,25 +638,25 @@ namespace Wox
UserSettingStorage.Instance.ProxyPassword = tbProxyPassword.Password;
UserSettingStorage.Instance.Save();
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("saveProxySuccessfully"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("saveProxySuccessfully"));
}
private void btnTestProxy_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(tbProxyServer.Text))
{
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("serverCantBeEmpty"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("serverCantBeEmpty"));
return;
}
if (string.IsNullOrEmpty(tbProxyPort.Text))
{
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("portCantBeEmpty"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("portCantBeEmpty"));
return;
}
int port;
if (!int.TryParse(tbProxyPort.Text, out port))
{
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("invalidPortFormat"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("invalidPortFormat"));
return;
}
@@ -687,16 +677,16 @@ namespace Wox
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("proxyIsCorrect"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyIsCorrect"));
}
else
{
MessageBox.Show(InternationalizationManager.Internationalization.GetTranslation("proxyConnectFailed"));
MessageBox.Show(InternationalizationManager.Instance.GetTranslation("proxyConnectFailed"));
}
}
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");
}
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="ImageLoader\ImageCacheStroage.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">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@@ -235,10 +230,6 @@
<SubType>Designer</SubType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Page Include="Update\NewVersionWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">