Skip to content

Commit

Permalink
Merge pull request #78 from jitwxs/dev
Browse files Browse the repository at this point in the history
implement upgrade version form && optimized program package
  • Loading branch information
jitwxs committed Apr 10, 2022
2 parents 3262bf7 + 3ae5d54 commit f5da4a0
Show file tree
Hide file tree
Showing 18 changed files with 5,005 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;

namespace MusicLyricApp.Utils
namespace MusicLyricApp.Bean
{
public static class Constants
{
public const string Version = "v4.1";

public static readonly string SettingPath = Environment.CurrentDirectory + "\\setting.json";
public static readonly string SettingPath = Environment.CurrentDirectory + "\\MusicLyricAppSetting.json";

public const int SettingFormOffset = 20;
}
Expand Down
115 changes: 115 additions & 0 deletions MusicLyricApp/Bean/GitHubBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace MusicLyricApp.Bean
{
public class GitHubInfo
{
[JsonProperty("message")] public string Message { get; set; }

[JsonProperty("url")] public Uri Url { get; set; }

[JsonProperty("assets_url")] public Uri AssetsUrl { get; set; }

[JsonProperty("upload_url")] public string UploadUrl { get; set; }

[JsonProperty("html_url")] public Uri HtmlUrl { get; set; }

[JsonProperty("id")] public long Id { get; set; }

[JsonProperty("author")] public Author Author { get; set; }

[JsonProperty("node_id")] public string NodeId { get; set; }

[JsonProperty("tag_name")] public string TagName { get; set; }

[JsonProperty("target_commitish")] public string TargetCommitish { get; set; }

[JsonProperty("name")] public string Name { get; set; }

[JsonProperty("draft")] public bool Draft { get; set; }

[JsonProperty("prerelease")] public bool Prerelease { get; set; }

[JsonProperty("created_at")] public DateTimeOffset CreatedAt { get; set; }

[JsonProperty("published_at")] public DateTimeOffset PublishedAt { get; set; }

[JsonProperty("assets")] public List<Asset> Assets { get; set; }

[JsonProperty("tarball_url")] public Uri TarballUrl { get; set; }

[JsonProperty("zipball_url")] public Uri ZipballUrl { get; set; }

[JsonProperty("body")] public string Body { get; set; }
}

public class Asset
{
[JsonProperty("url")] public Uri Url { get; set; }

[JsonProperty("id")] public long Id { get; set; }

[JsonProperty("node_id")] public string NodeId { get; set; }

[JsonProperty("name")] public string Name { get; set; }

[JsonProperty("label")] public object Label { get; set; }

[JsonProperty("uploader")] public Author Uploader { get; set; }

[JsonProperty("content_type")] public string ContentType { get; set; }

[JsonProperty("state")] public string State { get; set; }

[JsonProperty("size")] public long Size { get; set; }

[JsonProperty("download_count")] public long DownloadCount { get; set; }

[JsonProperty("created_at")] public DateTimeOffset CreatedAt { get; set; }

[JsonProperty("updated_at")] public DateTimeOffset UpdatedAt { get; set; }

[JsonProperty("browser_download_url")] public Uri BrowserDownloadUrl { get; set; }
}

public class Author
{
[JsonProperty("login")] public string Login { get; set; }

[JsonProperty("id")] public long Id { get; set; }

[JsonProperty("node_id")] public string NodeId { get; set; }

[JsonProperty("avatar_url")] public Uri AvatarUrl { get; set; }

[JsonProperty("gravatar_id")] public string GravatarId { get; set; }

[JsonProperty("url")] public Uri Url { get; set; }

[JsonProperty("html_url")] public Uri HtmlUrl { get; set; }

[JsonProperty("followers_url")] public Uri FollowersUrl { get; set; }

[JsonProperty("following_url")] public string FollowingUrl { get; set; }

[JsonProperty("gists_url")] public string GistsUrl { get; set; }

[JsonProperty("starred_url")] public string StarredUrl { get; set; }

[JsonProperty("subscriptions_url")] public Uri SubscriptionsUrl { get; set; }

[JsonProperty("organizations_url")] public Uri OrganizationsUrl { get; set; }

[JsonProperty("repos_url")] public Uri ReposUrl { get; set; }

[JsonProperty("events_url")] public string EventsUrl { get; set; }

[JsonProperty("received_events_url")] public Uri ReceivedEventsUrl { get; set; }

[JsonProperty("type")] public string Type { get; set; }

[JsonProperty("site_admin")] public bool SiteAdmin { get; set; }
}
}
2 changes: 1 addition & 1 deletion MusicLyricApp/Bean/MusicLyricsVO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public static class ErrorMsg

public const string GET_LATEST_VERSION_FAILED = "获取最新版本失败";
public const string THIS_IS_LATEST_VERSION = "当前版本已经是最新版本";
public const string EXIST_LATEST_VERSION = "检测到最新版本 {0},下载地址已复制到剪切板";
public const string SYSTEM_ERROR = "系统错误";
public const string NETWORK_ERROR = "网络错误,请检查网络链接";
public const string API_RATE_LIMIT = "请求过于频繁,请稍后再试";
}

/// <summary>
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions MusicLyricApp/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>
141 changes: 141 additions & 0 deletions MusicLyricApp/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeRuntimeReferences" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if runtime assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseRuntimeReferencePaths" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls whether the runtime assemblies are embedded with their full path or only with their assembly name.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCompression" type="xs:boolean">
<xs:annotation>
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCleanup" type="xs:boolean">
<xs:annotation>
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
3 changes: 2 additions & 1 deletion MusicLyricApp/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 42 additions & 18 deletions MusicLyricApp/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,17 @@ public partial class MainForm : Form

private SettingBean _settingBean;

private UpgradeForm _upgradeForm;

public MainForm()
{
// 禁止多开
var instance = new Mutex(true, "MutexName", out var isNotRunning);
if (!isNotRunning)
{
Environment.Exit(1);
}

InitializeComponent();
InitialConfig();
}
Expand Down Expand Up @@ -752,41 +761,56 @@ private void CheckLatestVersion(bool showMessageIfNotExistLatestVersion)
{
// support https
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var headers = new Dictionary<string, string>
{
{ "Accept", "application/vnd.github.v3+json" },
{ "User-Agent", BaseNativeApi.Useragent }
};

var jsonStr = HttpUtils.HttpGetAsync(
"https://api.github.com/repos/jitwxs/163MusicLyrics/releases/latest",
"application/json", headers).Result;

var jObject = (JObject)JsonConvert.DeserializeObject(jsonStr);
var latestTag = jObject["tag_name"];
"https://api.github.com/repos/jitwxs/163MusicLyrics/releases/latest",
"application/json",
new Dictionary<string, string>
{
{ "Accept", "application/vnd.github.v3+json" },
{ "User-Agent", BaseNativeApi.Useragent }
}).Result;

if (latestTag == null)
var info = JsonConvert.DeserializeObject<GitHubInfo>(jsonStr);
if (info == null)
{
MessageBox.Show(ErrorMsg.GET_LATEST_VERSION_FAILED, "提示");
return;
}

string bigV = latestTag.ToString().Substring(1, 2), smallV = latestTag.ToString().Substring(3);
if (info.Message != null && info.Message.Contains("API rate limit"))
{
MessageBox.Show(ErrorMsg.API_RATE_LIMIT, "提示");
return;
}

string bigV = info.TagName.Substring(1, 2), smallV = info.TagName.Substring(3);
string curBigV = Constants.Version.Substring(1, 2), curSmallV = Constants.Version.Substring(3);

if (bigV.CompareTo(curBigV) == 1 || (bigV.CompareTo(curBigV) == 0 && smallV.CompareTo(curSmallV) == 1))
{
Clipboard.SetDataObject("https://github.com/jitwxs/163MusicLyrics/releases");
MessageBox.Show(string.Format(ErrorMsg.EXIST_LATEST_VERSION, latestTag), "提示");
return;
void Action()
{
if (_upgradeForm == null || _upgradeForm.IsDisposed)
{
_upgradeForm = new UpgradeForm(info);
_upgradeForm.Location = new Point(Left + Constants.SettingFormOffset, Top + Constants.SettingFormOffset);
_upgradeForm.StartPosition = FormStartPosition.Manual;
_upgradeForm.Show();
}
else
{
_upgradeForm.Activate();
}
}
Invoke((Action)Action);
}

if (_showMessageIfNotExistLatestVersion)
else if (_showMessageIfNotExistLatestVersion)
{
MessageBox.Show(ErrorMsg.THIS_IS_LATEST_VERSION, "提示");
}
}
catch (HttpRequestException ex)
catch (System.Exception ex)
{
_logger.Error(ex);
MessageBox.Show(ErrorMsg.NETWORK_ERROR, "提示");
Expand Down
Loading

0 comments on commit f5da4a0

Please sign in to comment.