diff --git a/src/Dictionary.cs b/src/Dictionary.cs index 82c17b9..6e4d64b 100644 --- a/src/Dictionary.cs +++ b/src/Dictionary.cs @@ -151,8 +151,9 @@ private List DetailedQuery(Query query) results.Add(MakeResultItem("Definition", word.definition.Replace("\n", "; "), "d")); if (word.exchange != "") results.Add(MakeResultItem("Exchanges", word.exchange, "e")); - results.Add(MakeResultItem("Synonym", String.Join("; ", synonyms.Query(word.word)), "s")); - + var synonymsResult = String.Join("; ", synonyms.Query(word.word)); + if (synonymsResult != "") + results.Add(MakeResultItem("Synonym", synonymsResult, "s")); return results; } diff --git a/src/Downloader.cs b/src/Downloader.cs new file mode 100644 index 0000000..0aecc19 --- /dev/null +++ b/src/Downloader.cs @@ -0,0 +1,51 @@ +using SevenZip; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Dictionary +{ + class Downloader + { + const string URL = "https://coding.net/u/nullptr_t/p/ECDICT-sqlite/git/raw/master/ecdict.7z"; + string rootPath; + + public Downloader(string rootPath) + { + this.rootPath = rootPath; + } + + public void Download() + { + if (!File.Exists(rootPath + "dicts\\dict.7z.tmp")) + { + WebClient webClient = new WebClient(); + webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted; + webClient.DownloadFileAsync(new Uri(URL), rootPath + "dicts\\dict.7z.tmp"); + } + else + { + Decompress7Zip(rootPath + "dicts\\", "dict.7z.tmp"); + File.Delete(rootPath + "dicts\\dict.7z.tmp"); + } + } + + private void WebClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) + { + Decompress7Zip(rootPath + "dicts\\", "dict.7z.tmp"); + File.Delete(rootPath + "dicts\\dict.7z.tmp"); + } + + private void Decompress7Zip(string path, string fileName) + { + SevenZipExtractor.SetLibraryPath("7zxa.dll"); + new SevenZipExtractor(path + fileName).ExtractArchive(path); + MessageBox.Show("Download successfully", "Download successfully. Restart Wox to apply. 下载成功!请重启 Wox 来使用词典。"); + } + } +}