Skip to content

Commit

Permalink
added auto-updating
Browse files Browse the repository at this point in the history
  • Loading branch information
ErisLoona committed Jun 18, 2024
1 parent c1bc540 commit bff66d5
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Properties/PublishProfiles/FolderProfile.pubxml.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2024-06-18T16:11:20.9585577Z||;True|2024-06-18T17:54:04.9775606+02:00||;True|2024-06-18T17:53:03.5685184+02:00||;True|2024-06-18T17:52:26.3088028+02:00||;True|2024-06-17T11:12:58.4583359+02:00||;True|2024-06-17T10:36:25.6841440+02:00||;True|2024-06-14T11:31:32.6934516+02:00||;True|2024-06-14T11:31:23.3706499+02:00||;True|2024-06-14T11:31:18.7205494+02:00||;True|2024-06-13T09:43:43.5390795+02:00||;True|2024-06-13T08:57:35.0322797+02:00||;True|2024-06-06T15:42:28.6568298+02:00||;True|2024-06-06T15:40:12.6240419+02:00||;True|2024-06-06T13:48:19.4662781+02:00||;True|2024-06-06T12:38:52.6425012+02:00||;True|2024-06-06T12:31:36.7948282+02:00||;True|2024-06-06T10:35:12.1369025+02:00||;True|2024-06-06T10:34:54.5189019+02:00||;True|2024-06-05T23:32:06.1114024+02:00||;True|2024-05-27T18:47:08.3065316+02:00||;True|2024-05-27T18:43:26.7575713+02:00||;True|2024-05-27T16:16:44.1211325+02:00||;True|2024-05-27T16:16:29.4947310+02:00||;True|2024-05-27T11:07:49.8981157+02:00||;True|2024-05-27T11:07:01.1240671+02:00||;True|2024-05-27T11:06:53.1694382+02:00||;True|2024-05-27T09:10:47.9526993+02:00||;True|2024-05-27T09:10:02.8503554+02:00||;True|2024-05-27T09:09:35.2317189+02:00||;True|2024-05-27T08:58:09.8645241+02:00||;True|2024-05-27T08:52:52.8051920+02:00||;True|2024-05-27T08:45:19.6197985+02:00||;True|2024-05-24T11:02:27.2916636+02:00||;True|2024-05-24T08:59:01.6326756+02:00||;True|2024-05-23T09:17:13.9644300+02:00||;True|2024-05-23T09:05:46.2467509+02:00||;True|2024-05-22T22:13:45.9526537+02:00||;True|2024-05-22T22:09:03.4000755+02:00||;True|2024-05-22T22:08:00.0350517+02:00||;True|2024-05-22T21:44:48.4725626+02:00||;True|2024-05-22T21:32:35.3627900+02:00||;True|2024-05-22T19:33:34.6467061+02:00||;True|2024-05-19T19:19:28.1467287+02:00||;True|2024-05-19T19:17:09.7006733+02:00||;True|2024-05-19T19:14:06.6668981+02:00||;True|2024-05-19T14:42:07.1301968+02:00||;True|2024-05-19T14:38:02.4943907+02:00||;True|2024-05-19T09:20:51.2871097+02:00||;True|2024-05-19T09:18:16.6124371+02:00||;True|2024-05-19T09:15:08.6048404+02:00||;True|2024-05-18T22:34:28.8521894+02:00||;True|2024-05-18T22:22:14.4673452+02:00||;True|2024-05-18T21:56:58.6143811+02:00||;True|2024-05-18T07:41:43.4161277+02:00||;True|2024-05-17T11:48:43.3293227+02:00||;True|2024-05-17T09:31:58.9329403+02:00||;True|2024-05-17T09:25:57.4957904+02:00||;True|2024-05-16T19:52:10.0997229+02:00||;True|2024-05-16T18:17:01.7850021+02:00||;True|2024-05-15T09:33:00.6957135+02:00||;True|2024-05-15T08:32:31.7735956+02:00||;True|2024-05-13T17:25:21.1454345+02:00||;True|2024-05-13T17:15:09.7285346+02:00||;True|2024-05-13T16:52:20.9054581+02:00||;True|2024-05-13T16:51:27.0891569+02:00||;True|2024-05-13T16:50:34.5522468+02:00||;True|2024-05-13T16:49:22.6946988+02:00||;</History>
<History>True|2024-06-18T17:31:38.9594414Z||;True|2024-06-18T18:11:20.9585577+02:00||;True|2024-06-18T17:54:04.9775606+02:00||;True|2024-06-18T17:53:03.5685184+02:00||;True|2024-06-18T17:52:26.3088028+02:00||;True|2024-06-17T11:12:58.4583359+02:00||;True|2024-06-17T10:36:25.6841440+02:00||;True|2024-06-14T11:31:32.6934516+02:00||;True|2024-06-14T11:31:23.3706499+02:00||;True|2024-06-14T11:31:18.7205494+02:00||;True|2024-06-13T09:43:43.5390795+02:00||;True|2024-06-13T08:57:35.0322797+02:00||;True|2024-06-06T15:42:28.6568298+02:00||;True|2024-06-06T15:40:12.6240419+02:00||;True|2024-06-06T13:48:19.4662781+02:00||;True|2024-06-06T12:38:52.6425012+02:00||;True|2024-06-06T12:31:36.7948282+02:00||;True|2024-06-06T10:35:12.1369025+02:00||;True|2024-06-06T10:34:54.5189019+02:00||;True|2024-06-05T23:32:06.1114024+02:00||;True|2024-05-27T18:47:08.3065316+02:00||;True|2024-05-27T18:43:26.7575713+02:00||;True|2024-05-27T16:16:44.1211325+02:00||;True|2024-05-27T16:16:29.4947310+02:00||;True|2024-05-27T11:07:49.8981157+02:00||;True|2024-05-27T11:07:01.1240671+02:00||;True|2024-05-27T11:06:53.1694382+02:00||;True|2024-05-27T09:10:47.9526993+02:00||;True|2024-05-27T09:10:02.8503554+02:00||;True|2024-05-27T09:09:35.2317189+02:00||;True|2024-05-27T08:58:09.8645241+02:00||;True|2024-05-27T08:52:52.8051920+02:00||;True|2024-05-27T08:45:19.6197985+02:00||;True|2024-05-24T11:02:27.2916636+02:00||;True|2024-05-24T08:59:01.6326756+02:00||;True|2024-05-23T09:17:13.9644300+02:00||;True|2024-05-23T09:05:46.2467509+02:00||;True|2024-05-22T22:13:45.9526537+02:00||;True|2024-05-22T22:09:03.4000755+02:00||;True|2024-05-22T22:08:00.0350517+02:00||;True|2024-05-22T21:44:48.4725626+02:00||;True|2024-05-22T21:32:35.3627900+02:00||;True|2024-05-22T19:33:34.6467061+02:00||;True|2024-05-19T19:19:28.1467287+02:00||;True|2024-05-19T19:17:09.7006733+02:00||;True|2024-05-19T19:14:06.6668981+02:00||;True|2024-05-19T14:42:07.1301968+02:00||;True|2024-05-19T14:38:02.4943907+02:00||;True|2024-05-19T09:20:51.2871097+02:00||;True|2024-05-19T09:18:16.6124371+02:00||;True|2024-05-19T09:15:08.6048404+02:00||;True|2024-05-18T22:34:28.8521894+02:00||;True|2024-05-18T22:22:14.4673452+02:00||;True|2024-05-18T21:56:58.6143811+02:00||;True|2024-05-18T07:41:43.4161277+02:00||;True|2024-05-17T11:48:43.3293227+02:00||;True|2024-05-17T09:31:58.9329403+02:00||;True|2024-05-17T09:25:57.4957904+02:00||;True|2024-05-16T19:52:10.0997229+02:00||;True|2024-05-16T18:17:01.7850021+02:00||;True|2024-05-15T09:33:00.6957135+02:00||;True|2024-05-15T08:32:31.7735956+02:00||;True|2024-05-13T17:25:21.1454345+02:00||;True|2024-05-13T17:15:09.7285346+02:00||;True|2024-05-13T16:52:20.9054581+02:00||;True|2024-05-13T16:51:27.0891569+02:00||;True|2024-05-13T16:50:34.5522468+02:00||;True|2024-05-13T16:49:22.6946988+02:00||;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>
47 changes: 45 additions & 2 deletions mainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics;
using Flurl;
using System.IO;
using System.IO.Packaging;

namespace Manga_Library_Manager
{
Expand All @@ -29,7 +30,7 @@ public override string ToString()
}

public static string selectedLanguage;
public static bool noWarning;
public static bool noWarning, checkUpdates;
private List<eBook> books = new List<eBook>();
private AutoCompleteStringCollection searchTextBoxAutomcompleteStrings = new AutoCompleteStringCollection();
private List<string> files = new List<string>(), ratingsList = new List<string>();
Expand Down Expand Up @@ -86,6 +87,15 @@ private void mainMenu_Load(object sender, EventArgs e)
books = file.SelectToken("Library").ToObject<List<eBook>>();
selectedLanguage = file.SelectToken("Language").Value<string>();
noWarning = file.SelectToken("NoWarning").Value<bool>();
if (file.SelectToken("FormatVersion").Value<int>() > 2)
checkUpdates = file.SelectToken("CheckUpdates").Value<bool>();
else
{
if (MessageBox.Show("Would you like the program to automatically check for updates?\nYou can always change this later in the settings.", "Check for updates", MessageBoxButtons.YesNo) == DialogResult.No)
checkUpdates = false;
else
checkUpdates = true;
}
}
}
catch
Expand All @@ -98,6 +108,10 @@ private void mainMenu_Load(object sender, EventArgs e)
books = JsonConvert.DeserializeObject<List<eBook>>(line);
selectedLanguage = "en";
noWarning = false;
if (MessageBox.Show("Would you like the program to automatically check for updates?\nYou can always change this later in the settings.", "Check for updates", MessageBoxButtons.YesNo) == DialogResult.No)
checkUpdates = false;
else
checkUpdates = true;
}
goto ItJustWorks;
}
Expand Down Expand Up @@ -131,6 +145,7 @@ private void mainMenu_Load(object sender, EventArgs e)
{
selectedLanguage = "en";
noWarning = false;
checkUpdates = false;
books = JsonConvert.DeserializeObject<List<eBook>>(jsonDump);
MessageBox.Show("Import successful!\nYour settings have been reset.", "Import successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Expand All @@ -153,6 +168,33 @@ private void mainMenu_Load(object sender, EventArgs e)
}
}
ItJustWorks:
if (checkUpdates == true)
Task.Run(() =>
{
using HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.UserAgent.ParseAdd("Manga Library Manager for Windows by (github) ErisLoona");
try
{
JObject githubResponse = JObject.Parse(client.GetStringAsync("https://api.github.com/repos/erisloona/manga-library-manager/releases/latest").Result);
List<string> versionNumbers = new List<string>();
versionNumbers.AddRange(githubResponse.SelectToken("tag_name").Value<string>().Substring(1).Split("."));
string[] currentVersion = FileVersionInfo.GetVersionInfo(Environment.ProcessPath).FileVersion.Split(".");
bool update = false;
for (int i = 0; i < versionNumbers.Count; i++)
if (Convert.ToInt32(versionNumbers[i]) > Convert.ToInt32(currentVersion[i]))
{
update = true;
break;
}
if (update == true)
{
if (MessageBox.Show("A new version is available!\nWould you like to go download it?", "Update found", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
Process.Start(new ProcessStartInfo(githubResponse.SelectToken("html_url").Value<string>()) { UseShellExecute = true });
}
}
catch { }
});
mangaList.BeginUpdate();
foreach (eBook book in books)
{
Expand Down Expand Up @@ -1024,9 +1066,10 @@ private void mainMenu_FormClosing(object sender, FormClosingEventArgs e)
try
{
JObject saveFile = new JObject();
saveFile["FormatVersion"] = 2;
saveFile["FormatVersion"] = 3;
saveFile["Language"] = selectedLanguage;
saveFile["NoWarning"] = noWarning;
saveFile["CheckUpdates"] = checkUpdates;
saveFile["Library"] = JToken.FromObject(books);
using (StreamWriter writer = new StreamWriter("Manga Library Manager.json"))
{
Expand Down
25 changes: 20 additions & 5 deletions userSettings.Designer.cs

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

6 changes: 6 additions & 0 deletions userSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public userSettings()
private void userSettings_Load(object sender, EventArgs e)
{
warnCheckBox.Checked = !mainMenu.noWarning;
checkUpdatesCheckbox.Checked = mainMenu.checkUpdates;
foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
if (languages.ContainsValue(culture.TwoLetterISOLanguageName) == false)
languages[culture.EnglishName] = culture.TwoLetterISOLanguageName;
Expand All @@ -43,6 +44,11 @@ private void warnCheckBox_CheckedChanged(object sender, EventArgs e)
mainMenu.noWarning = !warnCheckBox.Checked;
}

private void checkUpdatesCheckbox_CheckedChanged(object sender, EventArgs e)
{
mainMenu.checkUpdates = checkUpdatesCheckbox.Checked;
}

private void importButton_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Warning! This will overwrite your entire current library!\nAre you sure you want to continue?", "Import library", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
Expand Down

0 comments on commit bff66d5

Please sign in to comment.