Skip to content

Commit

Permalink
完善检测更新机制,修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hupo376787 committed Nov 6, 2024
1 parent 92b17c7 commit a61e7e0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
6 changes: 1 addition & 5 deletions WeiboAlbumDownloader/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using Sentry;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;

Expand Down Expand Up @@ -50,6 +45,7 @@ private void OnStartup(object sender, StartupEventArgs e)
{
scope.SetTag("AppName", Assembly.GetExecutingAssembly().GetName().Name!);
scope.SetTag("DeviceName", Environment.MachineName);
scope.SetTag("AppVersion", GlobalVar.currentVersion.ToString("#0.0"));
});
}

Expand Down
2 changes: 2 additions & 0 deletions WeiboAlbumDownloader/GlobalVar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace WeiboAlbumDownloader
{
public class GlobalVar
{
public static double currentVersion = 3.7;

public static string gId = "";
public static long gSinceId;
public static int gPage;
Expand Down
41 changes: 24 additions & 17 deletions WeiboAlbumDownloader/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ namespace WeiboAlbumDownloader
public partial class MainWindow : MicaWindow
{
//发行说明:
//①此处升级一下版本号
//①此处升级一下GlobalVar版本号
//②Github/Gitee release新建一个新版本Tag
//③上传压缩包删除Settings.json以及uidList.txt
double currentVersion = 3.6;

/// <summary>
/// com1是根据uid获取相册id,https://photo.weibo.com/albums/get_all?uid=10000000000&page=1;根据uid和相册id以及相册type获取图片列表,https://photo.weibo.com/photos/get_all?uid=10000000000&album_id=3959362334782071&page=1&type=3
Expand Down Expand Up @@ -88,26 +87,34 @@ public MainWindow()

private async Task GetVersion()
{
AppendLog($"当前程序版本 V{currentVersion}");

//AppendLog($"当前程序版本 V{GlobalVar.currentVersion}");
var latestVersionString = await GithubHelper.GetLatestVersion();
if (string.IsNullOrEmpty(latestVersionString))
if (string.IsNullOrEmpty(latestVersionString) || latestVersionString?.Length > 5)
{
//AppendLog("从https://github.com/hupo376787/WeiboAlbumDownloader/releases获取最新版失败,请检查网络或稍后再试", MessageEnum.Warning);
latestVersionString = await GithubHelper.GetGiteeLatestVersion();
}
else
AppendLog($"当前程序版本 V{GlobalVar.currentVersion},最新版为 V{latestVersionString}");

var res = double.TryParse(latestVersionString, out double latestVersion);
if (res)
{
var res = double.TryParse(latestVersionString, out double latestVersion);
//获取成功
if (res)
{
if (latestVersion > currentVersion)
AppendLog($"Github最新版为V{latestVersion}。请从https://github.com/hupo376787/WeiboAlbumDownloader/releases获取最新版", MessageEnum.Success);
}
else
if (latestVersion > GlobalVar.currentVersion)
{
AppendLog("从https://github.com/hupo376787/WeiboAlbumDownloader/releases获取最新版失败,请检查网络或稍后再试", MessageEnum.Warning);
await Application.Current.Dispatcher.InvokeAsync(async () =>
{
var uiMessageBox = new MicaWPF.Dialogs.ContentDialog
{
Title = "提示",
Content = $"检测到新版本 V{latestVersionString},当前程序版本 V{GlobalVar.currentVersion},点击确定下载",
PrimaryButtonText = "OK"
};
var res = await uiMessageBox.ShowAsync();
if (res == MicaWPF.Core.Enums.ContentDialogResult.PrimaryButton)
{
Process.Start(new ProcessStartInfo("https://github.com/hupo376787/WeiboAlbumDownloader/releases") { UseShellExecute = true });
}
});
}
}
}
Expand Down Expand Up @@ -914,7 +921,7 @@ await Task.Run(async () =>
//单个用户结束下载
if (!string.IsNullOrEmpty(nickName))
{
string info = $"{nickName} <a href=\"//weibo.com/u/{userId}\">{userId}{nickName}</a>于{DateTime.Now.ToString("HH:mm:ss")}结束下载,程序版本V{currentVersion}<img src=\"{headUrl}\">";
string info = $"{nickName} <a href=\"//weibo.com/u/{userId}\">{userId}{nickName}</a>于{DateTime.Now.ToString("HH:mm:ss")}结束下载,程序版本V{GlobalVar.currentVersion}<img src=\"{headUrl}\">";
await PushPlusHelper.SendMessage(settings?.PushPlusToken!, "微博相册下载", info);
SentrySdk.CaptureMessage(info);
Expand Down
2 changes: 1 addition & 1 deletion WeiboAlbumDownloader/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void Confirm_Click(object sender, RoutedEventArgs e)
PushPlusToken = TextBox_PushPlusToken.Text,
EnableCrontab = (bool)ToggleSwitch_Crontab.IsChecked!,
Crontab = TextBox_Crontab.Text,
CountDownloadedSkipToNextUser = Convert.ToInt32(TextBox_SkipCount.Text)
CountDownloadedSkipToNextUser = string.IsNullOrEmpty(TextBox_SkipCount.Text) ? 20 : Convert.ToInt32(TextBox_SkipCount.Text)
};
File.WriteAllText("Settings.json", JsonConvert.SerializeObject(settings, Formatting.Indented));
this.Close();
Expand Down

0 comments on commit a61e7e0

Please sign in to comment.