Skip to content

Commit

Permalink
fixed a bug with the request (for no internet connection)
Browse files Browse the repository at this point in the history
  • Loading branch information
TorniX0 committed Feb 16, 2022
1 parent 5d8995b commit 3aa540e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
38 changes: 31 additions & 7 deletions src/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Globalization;
using System.Net.Http.Headers;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
Expand Down Expand Up @@ -38,7 +39,7 @@ public partial class MainWindow : Form
private uint NtActualResolution = 0;

private readonly static bool emptyBuildVersion = Assembly.GetEntryAssembly().GetName().Version.Build == -1;
private readonly string ProgramVersion = emptyBuildVersion ? Assembly.GetEntryAssembly().GetName().Version.Build.ToString() : "1.0.3.8";
private readonly string ProgramVersion = emptyBuildVersion ? Assembly.GetEntryAssembly().GetName().Version.Build.ToString() : "1.0.3.9";

private static Dictionary<string, int> Logger = new();

Expand Down Expand Up @@ -129,21 +130,44 @@ public MainWindow()

public string GetRequest(string uri, bool jsonaccept)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(uri);
HttpClient client = new();
client.BaseAddress = new(uri);
client.Timeout = new(0, 0, 4);

if (jsonaccept)
client.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));

var res = client.GetStringAsync(uri).Result;
string res = string.Empty;

try
{
res = client.GetStringAsync(uri).Result;
}
catch (AggregateException ex)
{
ex.Handle(x =>
{
if (x is HttpRequestException || x is SocketException)
{
return true;
}

return false;
});
}

return res;
}

public void CheckForUpdates()
{
string json = GetRequest("https://github.com/TorniX0/OpenTimerResolution/releases/latest", true);

if (json == string.Empty)
return;

var obj = JObject.Parse(json);
string ver = obj["tag_name"].ToString();
ver = ver.Substring(8, ver.Length - 8);
Expand Down Expand Up @@ -218,7 +242,7 @@ private void stopButton_Click(object sender, EventArgs e)
return;

var result = NtSetTimerResolution((int)(float.Parse(timerResolutionBox.Text) * 10000f), false, out NtCurrentResolution);

if (result != NtStatus.Success)
{
MessageBox.Show($"Error code: {result}", "OpenTimerResolution", MessageBoxButtons.OK, MessageBoxIcon.Error);
Expand Down Expand Up @@ -265,7 +289,7 @@ private void minimizeIcon_MouseClick(object sender, MouseEventArgs e)
this.ShowInTaskbar = true;
this.Show();
this.BringToFront();
this.WindowState = FormWindowState.Normal;
this.WindowState = FormWindowState.Normal;
}

private void quitStripMenu_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -475,4 +499,4 @@ private void updateConfigButton_Click(object sender, EventArgs e)

#endregion
}
}
}
6 changes: 3 additions & 3 deletions src/OpenTimerResolution.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<StartupObject>OpenTimerResolution.Program</StartupObject>
<ApplicationIcon>program.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AssemblyVersion>1.0.3.8</AssemblyVersion>
<FileVersion>1.0.3.8</FileVersion>
<Version>1.0.3.8</Version>
<AssemblyVersion>1.0.3.9</AssemblyVersion>
<FileVersion>1.0.3.9</FileVersion>
<Version>1.0.3.9</Version>
<DebugType>embedded</DebugType>
<Product>OpenTimerResolution</Product>
<Description>OpenTimerResolution is a lightweight open-source application that changes the resolution of the Windows system Timer to a specified value and has a memory cache cleaner included.</Description>
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/PublishProfiles/FolderProfile.pubxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net6.0-windows</TargetFramework>
<SelfContained>False</SelfContained>
<IncludeAllContentForSelfExtract>False</IncludeAllContentForSelfExtract>
<IncludeAllContentForSelfExtract>True</IncludeAllContentForSelfExtract>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
</PropertyGroup>
</Project>
</Project>

0 comments on commit 3aa540e

Please sign in to comment.