Skip to content

Commit

Permalink
Merge pull request #2964 from Wox-launcher/bao
Browse files Browse the repository at this point in the history
bunch of bug fix
  • Loading branch information
bao-qian authored May 19, 2020
2 parents 04b0a76 + 52ecd84 commit 7219524
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 82 deletions.
6 changes: 2 additions & 4 deletions Plugins/Wox.Plugin.Program/AddProgramSource.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

using Ookii.Dialogs.Wpf; // may be removed later https://github.com/dotnet/wpf/issues/438

using Wox.Plugin.Program.Views.Models;
using Wox.Plugin.Program.Views;


namespace Wox.Plugin.Program
Expand All @@ -15,7 +13,7 @@ namespace Wox.Plugin.Program
public partial class AddProgramSource
{
private PluginInitContext _context;
private Settings.ProgramSource _editing;
private ProgramSource _editing;
private Settings _settings;

public AddProgramSource(PluginInitContext context, Settings settings)
Expand All @@ -26,7 +24,7 @@ public AddProgramSource(PluginInitContext context, Settings settings)
Directory.Focus();
}

public AddProgramSource(Settings.ProgramSource edit, Settings settings)
public AddProgramSource(ProgramSource edit, Settings settings)
{
_editing = edit;
_settings = settings;
Expand Down
24 changes: 24 additions & 0 deletions Plugins/Wox.Plugin.Program/ProgramSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Wox.Plugin.Program
{
public class ProgramSource
{
public string Location { get; set; }

public override bool Equals(object obj)
{
var s = obj as ProgramSource;
return Location.Equals(s?.Location);
}

public override int GetHashCode()
{
return this.Location.GetHashCode();
}
}
}
37 changes: 23 additions & 14 deletions Plugins/Wox.Plugin.Program/Programs/UWP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ public Application(IAppxManifestApplication manifestApp, UWP package)
DisplayName = ResourcesFromPri(package.FullName, package.Name, DisplayName);
Description = ResourcesFromPri(package.FullName, package.Name, Description);
LogoUri = LogoUriFromManifest(manifestApp);
LogoPath = FilesFromPri(package.FullName, package.Name, LogoUri);
LogoPath = PathFromUri(package.FullName, package.Name, package.Location, LogoUri);

Enabled = true;
}

internal string ResourcesFromPri(string packageFullName, String packageName, string resourceReference)
internal string ResourcesFromPri(string packageFullName, string packageName, string resourceReference)
{
const string prefix = "ms-resource:";
string result = "";
Expand All @@ -382,7 +382,7 @@ internal string ResourcesFromPri(string packageFullName, String packageName, str
key = $"/{key}";
}

if (!key.ToLower().Contains("resources") && key.Count(c => c == '/') <= 3)
if (!key.ToLower().Contains("resources") && key.Count(c => c == '/') < 3)
{
key = $"/Resources{key}";
}
Expand All @@ -409,27 +409,36 @@ internal string ResourcesFromPri(string packageFullName, String packageName, str
return result;
}

private string FilesFromPri(string packageFullName, string packageName, string fileReference)
private string PathFromUri(string packageFullName, string packageName, string packageLocation, string fileReference)
{
// all https://msdn.microsoft.com/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets
// windows 10 https://msdn.microsoft.com/en-us/library/windows/apps/dn934817.aspx
// windows 8.1 https://msdn.microsoft.com/en-us/library/windows/apps/hh965372.aspx#target_size
// windows 8 https://msdn.microsoft.com/en-us/library/windows/apps/br211475.aspx

Logger.WoxTrace($"package: <{packageFullName}> file ref: <{fileReference}>");
string parsed = $"ms-resource://{packageName}/Files/{fileReference.Replace("\\", "/")}";
try
string path = Path.Combine(packageLocation, fileReference);
if (File.Exists(path))
{
string result = ResourceFromPriInternal(packageFullName, parsed);
Logger.WoxTrace($"package: <{packageFullName}> pri file result: <{result}>");
return result;
// for 28671Petrroll.PowerPlanSwitcher_0.4.4.0_x86__ge82akyxbc7z4
return path;
}
catch (Exception e)
else
{
e.Data.Add(nameof(fileReference), fileReference);
e.Data.Add(nameof(FilesFromPri) + nameof(parsed), parsed);
e.Data.Add(nameof(FilesFromPri) + nameof(packageFullName), packageFullName);
throw e;
string parsed = $"ms-resource://{packageName}/Files/{fileReference.Replace("\\", "/")}";
try
{
string result = ResourceFromPriInternal(packageFullName, parsed);
Logger.WoxTrace($"package: <{packageFullName}> pri file result: <{result}>");
return result;
}
catch (Exception e)
{
e.Data.Add(nameof(fileReference), fileReference);
e.Data.Add(nameof(PathFromUri) + nameof(parsed), parsed);
e.Data.Add(nameof(PathFromUri) + nameof(packageFullName), packageFullName);
throw e;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.Program/Programs/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private static string Extension(string path)
}
}

private static ParallelQuery<Win32> UnregisteredPrograms(List<Settings.ProgramSource> sources, string[] suffixes)
private static ParallelQuery<Win32> UnregisteredPrograms(List<ProgramSource> sources, string[] suffixes)
{
var paths = sources.Where(s => Directory.Exists(s.Location))
.SelectMany(s => ProgramPaths(s.Location, suffixes))
Expand Down
17 changes: 1 addition & 16 deletions Plugins/Wox.Plugin.Program/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,7 @@ public class Settings

internal const char SuffixSeperator = ';';

public class ProgramSource
{
public string Location { get; set; }

public override bool Equals(object obj)
{
var s = obj as ProgramSource;
var equality = s?.Location == Location ;
return equality;
}

public override int GetHashCode()
{
return this.Location.GetHashCode();
}
}


}
}
5 changes: 0 additions & 5 deletions Plugins/Wox.Plugin.Program/Views/Models/ProgramSource.cs

This file was deleted.

31 changes: 10 additions & 21 deletions Plugins/Wox.Plugin.Program/Views/ProgramSetting.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Wox.Plugin.Program.Views.Models;
using Wox.Plugin.Program.Programs;
using System.ComponentModel;
using System.Windows.Data;
Expand Down Expand Up @@ -52,23 +51,15 @@ private void ReIndexing()
private void btnAddProgramSource_OnClick(object sender, RoutedEventArgs e)
{
var add = new AddProgramSource(context, _settings);
if(add.ShowDialog() ?? false)
if (add.ShowDialog() ?? false)
{
ReIndexing();
}

programSourceView.Items.Refresh();
}

private void DeleteProgramSources(List<ProgramSource> itemsToDelete)
{
_settings.ProgramSources = _settings.ProgramSources.Where(s => itemsToDelete.Contains(s)).ToList();
ReIndexing();
}

private void btnEditProgramSource_OnClick(object sender, RoutedEventArgs e)
{
var selectedProgramSource = programSourceView.SelectedItem as Settings.ProgramSource;
var selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
if (selectedProgramSource != null)
{
var add = new AddProgramSource(selectedProgramSource, _settings);
Expand Down Expand Up @@ -127,15 +118,13 @@ private void programSourceView_Drop(object sender, DragEventArgs e)
Location = directory,
};

directoriesToAdd.Add(source);
directoriesToAdd.Add(source);
}
}

if (directoriesToAdd.Count() > 0)
{
directoriesToAdd.ForEach(x => _settings.ProgramSources.Add(x));

programSourceView.Items.Refresh();
ReIndexing();
}
}
Expand Down Expand Up @@ -165,12 +154,12 @@ private void btnProgramSoureDelete_OnClick(object sender, RoutedEventArgs e)
MessageBox.Show(msg);
return;
}

DeleteProgramSources(selectedItems);
ReIndexing();

programSourceView.SelectedItems.Clear();
programSourceView.Items.Refresh();
else
{
_settings.ProgramSources.RemoveAll(s => selectedItems.Contains(s));
programSourceView.SelectedItems.Clear();
ReIndexing();
}
}

private void ProgramSourceView_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
Expand Down Expand Up @@ -207,7 +196,7 @@ private void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e
var sortBy = columnBinding?.Path.Path ?? headerClicked.Column.Header as string;

Sort(sortBy, direction);

_lastHeaderClicked = headerClicked;
_lastDirection = direction;
}
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.Program/Wox.Plugin.Program.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<DependentUpon>AddProgramSource.xaml</DependentUpon>
</Compile>
<Compile Include="FileChangeWatcher.cs" />
<Compile Include="Views\Models\ProgramSource.cs" />
<Compile Include="ProgramSource.cs" />
<Compile Include="Programs\IProgram.cs" />
<Compile Include="Programs\UWP.cs" />
<Compile Include="Programs\Win32.cs" />
Expand Down
6 changes: 0 additions & 6 deletions Plugins/Wox.Plugin.WebSearch/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ public List<Result> Query(Query query)
};

results.Add(result);
ResultsUpdated?.Invoke(this, new ResultUpdatedEventArgs
{
Results = results,
Query = query
});

UpdateResultsFromSuggestion(results, keyword, subtitle, searchSource, query);
}
}
Expand Down
48 changes: 35 additions & 13 deletions Wox.Infrastructure/Alphabet.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Caching;
using NLog;
using ToolGood.Words;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.UserSettings;

namespace Wox.Infrastructure
Expand All @@ -12,6 +14,9 @@ public class Alphabet
{
private Settings _settings;
private MemoryCache _cache;

private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();
private static int count = 0;

public void Initialize()
{
Expand All @@ -25,23 +30,40 @@ public void Initialize()

public string Translate(string content)
{
string result = _cache[content] as string;
if (result == null)
if (_settings.ShouldUsePinyin)
{
if (_settings.ShouldUsePinyin && WordsHelper.HasChinese(content))
string result = _cache[content] as string;
if (result == null)
{
// todo change first pinyin to full pinyin list, but current fuzzy match algorithm won't support first char match
result = WordsHelper.GetFirstPinyin(content);
}
else
{
result = content;
if (count == 50)
{
// https://github.com/toolgood/ToolGood.Words/issues/53
GC.Collect();
}

if (WordsHelper.HasChinese(content))
{
// todo change first pinyin to full pinyin list, but current fuzzy match algorithm won't support first char match
result = WordsHelper.GetFirstPinyin(content);
if (count < 50)
{
count += 1;
}
}
else
{
result = content;
}
CacheItemPolicy policy = new CacheItemPolicy();
policy.SlidingExpiration = new TimeSpan(12, 0, 0);
_cache.Set(content, result, policy);
}
CacheItemPolicy policy = new CacheItemPolicy();
policy.SlidingExpiration = new TimeSpan(12, 0, 0);
_cache.Set(content, result, policy);
return result;
}
else
{
return content;
}
return result;
}
}
}
2 changes: 1 addition & 1 deletion Wox/ViewModel/SettingWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async void UpdateApp()
}
else
{
await _updater.UpdateApp(false);
await _updater.UpdateApp(false, Settings.UpdateToPrereleases);
}
}

Expand Down
5 changes: 5 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ artifacts:
- path: 'Output\Packages\Wox-*.*'
name: installer
- path: 'Output\Packages\RELEASES'
name: installer
- path: 'Wox.Installer\Everything*.exe'
name: installer
- path: 'Wox.Installer\python*.exe'
name: installer

0 comments on commit 7219524

Please sign in to comment.