-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Null
committed
Jan 27, 2018
1 parent
6d07276
commit 8b3ceec
Showing
2 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 来使用词典。"); | ||
} | ||
} | ||
} |