Skip to content

Commit

Permalink
fixed some issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Wampa842 committed Oct 31, 2019
1 parent ed425c6 commit 0b2baad
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.5.2
- Fixed (hopefully) an issue where the settings manager would try to write to a closed stream
- Added a "see what's new" button to the automatic update form
- Set the correct version because apparently I'm a doof
# 0.5.1
- Fixed some UI design issues
- Added PDB files for each assembly
Expand Down
2 changes: 1 addition & 1 deletion WPlugins.Common/About.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static class Info

static Info()
{
Version = new SemanticVersion(0, 5, 0);
Version = new SemanticVersion(0, 5, 2);
PluginDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
}
}
Expand Down
26 changes: 20 additions & 6 deletions WPlugins.Common/AutoUpdateForm.Designer.cs

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

5 changes: 5 additions & 0 deletions WPlugins.Common/AutoUpdateForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ private void AutoUpdateForm_FormClosed(object sender, FormClosedEventArgs e)
Settings.Save();
}

private void showChangelogLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
MessageBox.Show(VersionCheck.Description, "Changelog", MessageBoxButtons.OK);
}

private void privacyLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string note =
Expand Down
26 changes: 23 additions & 3 deletions WPlugins.Common/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ You should have received a copy of the GNU General Public License
using System.Xml;
using System.Xml.Serialization;

// TODO: Rewrite the code that opens/closes

namespace WPlugins.Common
{
public static class Settings
Expand Down Expand Up @@ -63,8 +65,16 @@ public static SettingsData Import(string path)
if (_stream == null)
_stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
reader = XmlReader.Create(_stream);

settings = (SettingsData)_serializer.Deserialize(reader);
try
{
settings = (SettingsData)_serializer.Deserialize(reader);
}
catch(ObjectDisposedException)
{
_stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
reader = XmlReader.Create(_stream);
settings = (SettingsData)_serializer.Deserialize(reader);
}
}
catch (Exception ex)
{
Expand Down Expand Up @@ -100,7 +110,17 @@ public static void Export(string path, SettingsData settings)
_stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
writer = XmlWriter.Create(_stream);

_serializer.Serialize(writer, settings);
try
{
_serializer.Serialize(writer, settings);
}
catch(ObjectDisposedException)
{
// This code is all kinds of fucked. I need to get a grip on streams.
_stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
writer = XmlWriter.Create(_stream);
_serializer.Serialize(writer, settings);
}
}
catch (Exception ex)
{
Expand Down
21 changes: 20 additions & 1 deletion WPlugins.Common/VersionCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ public static class VersionCheck
{
public const string RELEASE_URL = "https://api.github.com/repos/wampa842/wplugins/releases/latest";

private static string _description;
public static string Description
{
get
{
if(string.IsNullOrEmpty(_description))
{
GetLatestVersion();
}
return _description;
}
}

// Extract the semver string from the JSON file from GitHub's web API. The return value indicates whether the operation was successful.
private static bool GetVersionString(string content, out string version)
{
Expand All @@ -39,7 +52,13 @@ private static bool GetVersionString(string content, out string version)
return false;
}

Match regex = Regex.Match(content, "\"tag_name\"[\\s:]*\"([\\d.]*)\"");
Match regex = Regex.Match(content, "\"body\":.?\"(.*)\"");
if(regex.Success)
{
_description = regex.Groups[1].ToString().Replace("\\n", "\n").Replace("\\r", "");
}

regex = Regex.Match(content, "\"tag_name\"[\\s:]*\"([\\d.]*)\"");
if(regex.Success)
{
version = regex.Groups[1].ToString();
Expand Down

0 comments on commit 0b2baad

Please sign in to comment.