Skip to content

Commit

Permalink
Merge pull request #33 from Khiro95/dev
Browse files Browse the repository at this point in the history
Update to v3.3
  • Loading branch information
Khiro95 authored Oct 2, 2024
2 parents 10f5969 + 9f5dc17 commit 678be61
Show file tree
Hide file tree
Showing 93 changed files with 2,671 additions and 282 deletions.
8 changes: 8 additions & 0 deletions AwqatSalaat.Common/Data/CalendarType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace AwqatSalaat.Data
{
public enum CalendarType
{
UmAlQura,
Hijri
}
}
147 changes: 108 additions & 39 deletions AwqatSalaat.Common/Helpers/HijriDateHelper.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,109 @@
using System;
using AwqatSalaat.Properties;
using System;
using System.Globalization;
using System.Linq;

namespace AwqatSalaat.Helpers
{
public static class HijriDateHelper
{
private static readonly DateTimeFormatInfo FallbackHijriDateTimeFormatInfo;
private static readonly DateTimeFormatInfo s_ArabicUmAlQuraDateTimeFormatInfo;
private static readonly DateTimeFormatInfo s_EnglishUmAlQuraDateTimeFormatInfo;
private static readonly DateTimeFormatInfo s_ArabicHijriDateTimeFormatInfo;
private static readonly DateTimeFormatInfo s_EnglishHijriDateTimeFormatInfo;
private static readonly HijriCalendar s_HijriCalendar = new HijriCalendar();

static HijriDateHelper()
{
// Start with the Arabic culture info since it provide all features
var dateTimeFormat = new CultureInfo("ar-SA").DateTimeFormat;
// Use English names as a fallback
dateTimeFormat.MonthNames = new string[]
var englishHijriMonths = new string[]
{
"Muharram",
"Safar",
"Rabiʻ I",
"Rabiʻ II",
"Jumada I",
"Jumada II",
"Rajab",
"Shaʻban",
"Ramadan",
"Shawwal",
"Dhuʻl-Qiʻdah",
"Dhuʻl-Hijjah",
""
"Muharram",
"Safar",
"Rabiʻ I",
"Rabiʻ II",
"Jumada I",
"Jumada II",
"Rajab",
"Shaʻban",
"Ramadan",
"Shawwal",
"Dhuʻl-Qiʻdah",
"Dhuʻl-Hijjah",
""
};
// MonthGenitiveNames is what provide values for formatter
dateTimeFormat.MonthGenitiveNames = dateTimeFormat.MonthNames;

FallbackHijriDateTimeFormatInfo = dateTimeFormat;
// Init Arabc DateTimeFormatInfo for Um Al Qura calendar
var arSA = new CultureInfo("ar-SA");
s_ArabicUmAlQuraDateTimeFormatInfo = arSA.DateTimeFormat;

if (!(arSA.Calendar is UmAlQuraCalendar))
{
var umalqura = arSA.OptionalCalendars.Single(c => c is UmAlQuraCalendar);
s_ArabicUmAlQuraDateTimeFormatInfo.Calendar = umalqura;
}



// Init English DateTimeFormatInfo for Um Al Qura calendar
var enSA = new CultureInfo("en-SA");

if (enSA.OptionalCalendars.Any(c => c is UmAlQuraCalendar))
{
s_EnglishUmAlQuraDateTimeFormatInfo = enSA.DateTimeFormat;

if (!(enSA.Calendar is UmAlQuraCalendar))
{
var umalqura = enSA.OptionalCalendars.Single(c => c is UmAlQuraCalendar);
s_EnglishUmAlQuraDateTimeFormatInfo.Calendar = umalqura;
}
}
else
{
// Start with the Arabic culture info since it provide all features
var dateTimeFormat = new CultureInfo("ar-SA").DateTimeFormat;
// Set English names
dateTimeFormat.MonthNames = englishHijriMonths;
// MonthGenitiveNames is what provide values for formatter
dateTimeFormat.MonthGenitiveNames = dateTimeFormat.MonthNames;

s_EnglishUmAlQuraDateTimeFormatInfo = dateTimeFormat;
}



// Init Arabic DateTimeFormatInfo for Hijri calendar
arSA = new CultureInfo("ar-SA");
arSA.DateTimeFormat.Calendar = s_HijriCalendar;
s_ArabicHijriDateTimeFormatInfo = arSA.DateTimeFormat;



// Init English DateTimeFormatInfo for Hijri calendar
enSA = new CultureInfo("en-SA");

if (enSA.OptionalCalendars.Any(c => c is HijriCalendar))
{
enSA.DateTimeFormat.Calendar = s_HijriCalendar;
s_EnglishHijriDateTimeFormatInfo = enSA.DateTimeFormat;
}
else
{
// Start with the Arabic culture info since it provide all features
var dateTimeFormat = new CultureInfo("ar-SA").DateTimeFormat;
dateTimeFormat.Calendar = s_HijriCalendar;
// Set English names
dateTimeFormat.MonthNames = englishHijriMonths;
// MonthGenitiveNames is what provide values for formatter
dateTimeFormat.MonthGenitiveNames = dateTimeFormat.MonthNames;

s_EnglishHijriDateTimeFormatInfo = dateTimeFormat;
}



Settings.Default.SettingsLoaded += (_, __) => s_HijriCalendar.HijriAdjustment = Settings.Default.HijriAdjustment;
Settings.Default.SettingsSaving += (_, __) => s_HijriCalendar.HijriAdjustment = Settings.Default.HijriAdjustment;
s_HijriCalendar.HijriAdjustment = Settings.Default.HijriAdjustment;
}

public static string Format(DateTime dateTime, string format, string language)
Expand All @@ -41,30 +113,27 @@ public static string Format(DateTime dateTime, string format, string language)
language = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
}

if (language.Length > 2)
{
language = language.Substring(0, 2);
}
CultureInfo culture = CultureInfo.GetCultureInfo(language);

language += "-SA";
DateTimeFormatInfo dateTimeFormat = GetProperDateTimeFormatInfo(culture);

CultureInfo culture = CultureInfo.GetCultureInfo(language);
return dateTime.ToString(format, dateTimeFormat);
}

DateTimeFormatInfo dateTimeFormat = culture.DateTimeFormat;
private static DateTimeFormatInfo GetProperDateTimeFormatInfo(CultureInfo culture)
{
var calendarType = Settings.Default.CalendarType;

if (dateTimeFormat.Calendar.GetType() != typeof(UmAlQuraCalendar))
if (calendarType == Data.CalendarType.UmAlQura)
{
if (culture.TextInfo.IsRightToLeft)
{
dateTimeFormat = CultureInfo.GetCultureInfo("ar-SA").DateTimeFormat;
}
else
{
dateTimeFormat = FallbackHijriDateTimeFormatInfo;
}
return culture.TextInfo.IsRightToLeft ? s_ArabicUmAlQuraDateTimeFormatInfo : s_EnglishUmAlQuraDateTimeFormatInfo;
}
else if (calendarType == Data.CalendarType.Hijri)
{
return culture.TextInfo.IsRightToLeft ? s_ArabicHijriDateTimeFormatInfo : s_EnglishHijriDateTimeFormatInfo;
}

return dateTime.ToString(format, dateTimeFormat);
throw new InvalidOperationException("Invalid calendar type.");
}
}
}
5 changes: 4 additions & 1 deletion AwqatSalaat.Common/Helpers/SystemInfos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ public static bool IsTaskBarWidgetsEnabled()
{
if (key != null)
{
int value = Convert.ToInt32(key.GetValue("TaskbarDa", 0));
int value = Convert.ToInt32(key.GetValue("TaskbarDa", 1));
return value == 1;
}
}

// Widgets button is enabled by default in Windows 11
return true;
}

return false;
Expand Down
68 changes: 64 additions & 4 deletions AwqatSalaat.Common/Interop/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ public static class User32

[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr HWND, string lpText, string lpCaption, uint uType);
public static int MessageBox(IntPtr HWND, string lpText, string lpCaption, MessageBoxButtons buttons)
=> MessageBox(HWND, lpText, lpCaption, (uint)buttons);
public static int MessageBox(IntPtr HWND, string lpText, string lpCaption, MessageBoxButtons buttons, MessageBoxIcon icon)
=> MessageBox(HWND, lpText, lpCaption, (uint)buttons | (uint)icon);

[DllImport("user32.dll")]
public static extern uint GetDpiForWindow([In] IntPtr hWnd);
Expand Down Expand Up @@ -88,6 +84,18 @@ public static extern IntPtr CreateWindowEx(

[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos([In] IntPtr hWnd, [In, Optional] IntPtr hWndInsertAfter, [In] int X, [In] int Y, [In] int cx, [In] int cy, [In] SWP uFlags);

[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetCursorPos([In] int x, [In] int y);

[DllImport("user32.dll", SetLastError = true)]
public static extern bool GetCursorPos([Out] out POINT lpPoint);

[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetForegroundWindow();

[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetForegroundWindow([In] IntPtr hWnd);
}

public static class Dwmapi
Expand All @@ -112,6 +120,9 @@ public static class Kernel32
{
[DllImport("kernel32.dll")]
public static extern IntPtr GetModuleHandle(string module);

[DllImport("kernel32.dll")]
public static extern IntPtr RegisterApplicationRestart(string pwzCommandline, ApplicationRestart dwFlags = ApplicationRestart.None);
}

[Flags]
Expand Down Expand Up @@ -174,6 +185,32 @@ public enum MessageBoxIcon : uint
MB_ICONSTOP = MB_ICONHAND,
}

public enum MessageBoxResult : uint
{
// NONE is not a standard value, I added it to simplify things
NONE = 0,
IDOK = 1,
IDCANCEL = 2,
IDABORT = 3,
IDRETRY = 4,
IDIGNORE = 5,
IDYES = 6,
IDNO = 7,
}

[Flags]
public enum MessageBoxOptions : uint
{
// NONE is not a standard value, I added it to simplify things
NONE = 0,
MB_SETFOREGROUND = 0x00010000,
MB_DEFAULT_DESKTOP_ONLY = 0x00020000,
MB_TOPMOST = 0x00040000,
MB_RIGHT = 0x00080000,
MB_RTLREADING = 0x00100000,
MB_SERVICE_NOTIFICATION = 0x00200000,
}

[Flags]
public enum SWP : uint
{
Expand Down Expand Up @@ -344,6 +381,7 @@ public enum AlphaFormat : byte
public enum WindowMessage : uint
{
WM_SETREDRAW = 0x000B,
WM_QUERYENDSESSION = 0x0011,
WM_SETTINGCHANGE = 0x001A
}

Expand Down Expand Up @@ -460,4 +498,26 @@ public enum DWMNCRENDERINGPOLICY
/// </summary>
DWMNCRP_LAST
};

[Flags]
public enum ApplicationRestart
{
None = 0,
/// <summary>
/// Do not restart the process if it terminates due to an unhandled exception.
/// </summary>
RESTART_NO_CRASH = 1,
/// <summary>
/// Do not restart the process if it terminates due to the application not responding.
/// </summary>
RESTART_NO_HANG = 2,
/// <summary>
/// Do not restart the process if it terminates due to the installation of an update.
/// </summary>
RESTART_NO_PATCH = 4,
/// <summary>
/// Do not restart the process if the computer is restarted as the result of an update.
/// </summary>
RESTART_NO_REBOOT = 8,
}
}
Loading

0 comments on commit 678be61

Please sign in to comment.