Skip to content

Commit 35cf82d

Browse files
committed
region check
1 parent af9bdcf commit 35cf82d

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

OpenHardwareMonitor/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23
using System.Threading;
34
using System.Windows.Forms;
45
using OpenHardwareMonitor.UI;
@@ -12,6 +13,12 @@ public static class Program
1213
[STAThread]
1314
public static void Main()
1415
{
16+
if ("RU".Equals(RegionHelper.GetGeoInfo(SysGeoType.GEO_ISO2)) ||
17+
"RU".Equals(RegionInfo.CurrentRegion.Name))
18+
{
19+
MessageBox.Show("The application is not compatible with russia region.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
20+
Environment.Exit(0);
21+
}
1522
if (!mutex.WaitOne(TimeSpan.Zero, true))
1623
{
1724
MessageBox.Show("Another instance of the application is already running.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Runtime.InteropServices;
2+
using System.Text;
3+
4+
namespace OpenHardwareMonitor;
5+
6+
public enum SysGeoType {
7+
GEO_NATION = 0x0001,
8+
GEO_LATITUDE = 0x0002,
9+
GEO_LONGITUDE = 0x0003,
10+
GEO_ISO2 = 0x0004,
11+
GEO_ISO3 = 0x0005,
12+
GEO_RFC1766 = 0x0006,
13+
GEO_LCID = 0x0007,
14+
GEO_FRIENDLYNAME = 0x0008,
15+
GEO_OFFICIALNAME = 0x0009,
16+
GEO_TIMEZONES = 0x000A,
17+
GEO_OFFICIALLANGUAGES = 0x000B,
18+
GEO_ISO_UN_NUMBER = 0x000C,
19+
GEO_PARENT = 0x000D,
20+
GEO_DIALINGCODE = 0x000E,
21+
GEO_CURRENCYCODE = 0x000F,
22+
GEO_CURRENCYSYMBOL = 0x0010,
23+
GEO_NAME = 0x0011,
24+
GEO_ID = 0x0012
25+
}
26+
27+
public static class RegionHelper
28+
{
29+
private enum GeoClass
30+
{
31+
Nation = 16,
32+
Region = 14,
33+
};
34+
35+
[DllImport("kernel32.dll", ExactSpelling = true, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
36+
private static extern int GetUserGeoID(GeoClass geoClass);
37+
38+
[DllImport("kernel32.dll")]
39+
private static extern int GetUserDefaultLCID();
40+
41+
[DllImport("kernel32.dll")]
42+
private static extern int GetGeoInfo(int geoid, int geoType, StringBuilder lpGeoData, int cchData, int langid);
43+
44+
public static string GetGeoInfo(SysGeoType geoType = SysGeoType.GEO_FRIENDLYNAME)
45+
{
46+
int geoId = GetUserGeoID(GeoClass.Nation);
47+
int lcid = GetUserDefaultLCID();
48+
var buffer = new StringBuilder(100);
49+
GetGeoInfo(geoId, (int)geoType, buffer, buffer.Capacity, lcid);
50+
return buffer.ToString().Trim();
51+
}
52+
}

0 commit comments

Comments
 (0)