diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 812791a..2737564 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,7 +32,6 @@ jobs: cd ../../../ Remove-Item public -Recurse -ErrorAction Ignore mkdir public - Copy-Item version.txt ./public/ -force mv ./Gevjon-Core/bin/Release/Gevjon.7z ./public/ - name: Upload artifact @@ -42,20 +41,6 @@ jobs: retention-days: 1 path: | public/Gevjon.7z - public/version.txt - - - name: Deploy - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./public - keep_files: true - - - name: Purge CDN cache - if: github.ref == 'refs/heads/master' - run: | - curl https://purge.jsdelivr.net/gh/RyoLee/Gevjon@gh-pages/version.txt - curl https://purge.jsdelivr.net/gh/RyoLee/Gevjon@gh-pages/Gevjon.7z release: needs: build @@ -67,9 +52,20 @@ jobs: with: name: Gevjon path: public - - name: Set Version + - name: Pack run: | - VER=$(head -n 1 public/version.txt) + mkdir -p ./pack + mv ./public/Gevjon.7z ./pack/ + cd ./pack + 7z x Gevjon.7z + rm Gevjon.7z -f + wget -q -O - https://ygocdb.com/api/v0/cards.zip | gunzip - > ./cards.json + wget -q -O ./cards.ver https://ygocdb.com/api/v0/cards.zip.md5 + 7z a Gevjon.7z * + cd .. + mv ./pack/version.txt ./public/ + mv ./pack/Gevjon.7z ./public/ + VER=$(head -n 1 ./public/version.txt) echo "TAG_NAME=$VER" >> $GITHUB_ENV CONTENT="Checksum(SHA256): "$(sha256sum public//Gevjon.7z | awk '{print $1}') echo "DEFAULT_CONTENT=$CONTENT" >> $GITHUB_ENV @@ -80,3 +76,16 @@ jobs: generate_release_notes: true tag_name: ${{ env.TAG_NAME }} files: public/Gevjon.7z + + - name: Deploy github pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./public + keep_files: true + + - name: Purge CDN cache + if: github.ref == 'refs/heads/master' + run: | + curl https://purge.jsdelivr.net/gh/RyoLee/Gevjon@gh-pages/version.txt + curl https://purge.jsdelivr.net/gh/RyoLee/Gevjon@gh-pages/Gevjon.7z \ No newline at end of file diff --git a/Gevjon-Core/App.config b/Gevjon-Core/App.config index 141fc08..6d5f4e9 100644 --- a/Gevjon-Core/App.config +++ b/Gevjon-Core/App.config @@ -13,6 +13,8 @@ + + diff --git a/Gevjon-Core/Gevjon.csproj b/Gevjon-Core/Gevjon.csproj index 8b1885b..9a3b1bf 100644 --- a/Gevjon-Core/Gevjon.csproj +++ b/Gevjon-Core/Gevjon.csproj @@ -117,6 +117,8 @@ + + @@ -196,6 +198,7 @@ xcopy "$(SolutionDir)Gevjon-Core\cards.json" "$(TargetDir)" /Y +xcopy "$(SolutionDir)Gevjon-Core\cards.ver" "$(TargetDir)" /Y xcopy "$(SolutionDir)README.md" "$(TargetDir)" /Y xcopy "$(SolutionDir)version.txt" "$(TargetDir)" /Y diff --git a/Gevjon-Core/cards.ver b/Gevjon-Core/cards.ver new file mode 100644 index 0000000..98349b5 --- /dev/null +++ b/Gevjon-Core/cards.ver @@ -0,0 +1 @@ +"9ac9f993be8eed795caedc2fa55c7d30" \ No newline at end of file diff --git a/Gevjon-Core/mainwindow.xaml.cs b/Gevjon-Core/mainwindow.xaml.cs index 664326e..3d044bd 100644 --- a/Gevjon-Core/mainwindow.xaml.cs +++ b/Gevjon-Core/mainwindow.xaml.cs @@ -31,6 +31,7 @@ using System.Web.Script.Serialization; using System.Threading.Tasks; using System.IO; +using System.IO.Compression; namespace Gevjon { @@ -158,8 +159,7 @@ public class YGOdb static string dbFile = "cards.json"; Dictionary datas; - public YGOdb() - { + public void reload() { datas = new Dictionary(); using (StreamReader file = File.OpenText(dbFile)) { @@ -197,6 +197,10 @@ public YGOdb() } } } + public YGOdb() + { + reload(); + } public List Find(string key,bool exact) { List cards = new List(); @@ -498,19 +502,50 @@ private async Task CheckUpdate() string HITS_URL = "https://hits.dwyl.com/RyoLee/Gevjon.svg"; string VER_URL = GetSetting("verURL", "https://cdn.jsdelivr.net/gh/RyoLee/Gevjon@gh-pages/version.txt"); string REL_URL = GetSetting("dlURL", "https://cdn.jsdelivr.net/gh/RyoLee/Gevjon@gh-pages/Gevjon.7z"); + string DATA_VER_URL = GetSetting("dataVerURL", "https://ygocdb.com/api/v0/cards.zip.md5"); + string DATA_REL_URL = GetSetting("dataDlURL", "https://ygocdb.com/api/v0/cards.zip"); string remote_ver_str = await TryGetAsync(VER_URL); string locale_ver_str; - using (StreamReader reader = new StreamReader("version.txt")) { + using (StreamReader reader = new StreamReader("version.txt")) + { locale_ver_str = reader.ReadLine() ?? ""; } var remote_ver = new Version(remote_ver_str); var locale_ver = new Version(locale_ver_str); - if (remote_ver.CompareTo(locale_ver)==1) { - if (MessageBox.Show("本地:\t" + locale_ver_str + "\n远端:\t" + remote_ver_str + "\n是否更新?", "发现新版本", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { + if (remote_ver.CompareTo(locale_ver) == 1) + { + if (MessageBox.Show("本地:\t" + locale_ver_str + "\n远端:\t" + remote_ver_str + "\n是否更新?", "发现新版本", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) + { await TryGetAsync(HITS_URL); System.Diagnostics.Process.Start(REL_URL); } } + string remote_data_ver_str = await TryGetAsync(DATA_VER_URL); + string locale_data_ver_str; + using (StreamReader reader = new StreamReader("cards.ver")) + { + locale_data_ver_str = reader.ReadLine() ?? ""; + } + if (!locale_data_ver_str.Equals(remote_data_ver_str)) + { + if (MessageBox.Show("本地卡片数据与服务器不一致\n是否更新?", "发现新数据", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) + { + await TryGetAsync(HITS_URL); + using (var client = new System.Net.WebClient()) + { + client.DownloadFile(DATA_REL_URL, "cards.zip"); + using (var zipArchive = ZipFile.OpenRead("cards.zip")) + { + foreach (ZipArchiveEntry entry in zipArchive.Entries) + { + entry.ExtractToFile(entry.Name, true); + } + } + client.DownloadFile(DATA_VER_URL, "cards.ver"); + db.reload(); + } + } + } } finally { System.Threading.Monitor.Exit(UpdateCheckBox); diff --git a/version.txt b/version.txt index 589268e..6261a05 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.3.0 \ No newline at end of file +1.3.1 \ No newline at end of file