()
| 113 | } |
| 114 | |
| 115 | static async Task<Update> FetchUpdate() |
| 116 | { |
| 117 | try |
| 118 | { |
| 119 | var json = await DownloadString(ApiUrl); |
| 120 | var match = new Regex("\"tag_name\":\\s+\"(.*)\"").Match(json); |
| 121 | |
| 122 | if (match.Success && match.Groups.Count > 1) |
| 123 | { |
| 124 | var vtag = match.Groups[1].Value.ToLower(); |
| 125 | if (vtag.StartsWith("v")) |
| 126 | vtag = vtag.Substring(1); |
| 127 | |
| 128 | var remote = new Version(vtag); |
| 129 | var local = new Version(Program.VERSION); |
| 130 | |
| 131 | if (remote.CompareTo(local) > 0) |
| 132 | { |
| 133 | string changes = ""; |
| 134 | match = new Regex("\"body\":\\s+\"(.*)\"").Match(json); |
| 135 | if (match.Success && match.Groups.Count > 1) |
| 136 | changes = Regex.Unescape(match.Groups[1].Value); |
| 137 | |
| 138 | string downloadUrl = ""; |
| 139 | match = new Regex("\"browser_download_url\":\\s+\"(.*(\\d+\\.?)(?:-stable)?\\.zip)\"").Match(json); |
| 140 | if (match.Success && match.Groups.Count > 1) |
| 141 | downloadUrl = Regex.Unescape(match.Groups[1].Value); |
| 142 | |
| 143 | return new Update |
| 144 | { |
| 145 | Version = vtag, |
| 146 | Changes = changes, |
| 147 | DownloadUrl = downloadUrl |
| 148 | }; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return null; |
| 153 | } |
| 154 | catch (Exception ex) |
| 155 | { |
| 156 | MessageBox.Show(MainWindow.Instance, |
| 157 | "Failed to check update.\n" + ex.Message, |
| 158 | Program.Name, MessageBoxButton.OK, MessageBoxImage.Warning); |
| 159 | return null; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | static async Task<string> DownloadString(string url) |
| 164 | { |
nothing calls this directly
no outgoing calls
no test coverage detected