Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Dec 15, 2024
1 parent 2610110 commit c52a150
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions JL.Core/Audio/AudioUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static class AudioUtils

if (urlStr is not null)
{
urlStr = urlStr.Replace("://localhost", "://127.0.0.1", StringComparison.Ordinal);
urlStr = urlStr.Replace("://localhost", "://127.0.0.1", StringComparison.OrdinalIgnoreCase);
if (Uri.TryCreate(urlStr, UriKind.Absolute, out Uri? resultUrl))
{
AudioResponse? audioResponse = await GetAudioFromUrl(resultUrl).ConfigureAwait(false);
Expand Down Expand Up @@ -138,12 +138,12 @@ public static class AudioUtils
case AudioSourceType.Url:
case AudioSourceType.UrlJson:
{
StringBuilder stringBuilder = new StringBuilder(uri)
.Replace("://localhost", "://127.0.0.1")
.Replace("{Term}", spelling)
.Replace("{Reading}", reading);
string normalizedUriStr = uri
.Replace("://localhost", "://127.0.0.1", StringComparison.OrdinalIgnoreCase)
.Replace("{Term}", spelling, StringComparison.OrdinalIgnoreCase)
.Replace("{Reading}", reading, StringComparison.OrdinalIgnoreCase);

Uri normalizedUri = new(stringBuilder.ToString());
Uri normalizedUri = new(normalizedUriStr);
audioResponse = audioSource.Type is AudioSourceType.Url
? await GetAudioFromUrl(normalizedUri).ConfigureAwait(false)
: await GetAudioFromJsonReturningUrl(normalizedUri).ConfigureAwait(false);
Expand All @@ -153,11 +153,11 @@ public static class AudioUtils

case AudioSourceType.LocalPath:
{
StringBuilder stringBuilder = new StringBuilder(uri)
.Replace("{Term}", spelling)
.Replace("{Reading}", reading);
string normalizedUriStr = uri
.Replace("{Term}", spelling, StringComparison.OrdinalIgnoreCase)
.Replace("{Reading}", reading, StringComparison.OrdinalIgnoreCase);

Uri normalizedUri = new(stringBuilder.ToString());
Uri normalizedUri = new(normalizedUriStr);
audioResponse = await GetAudioFromPath(normalizedUri).ConfigureAwait(false);

break;
Expand Down
4 changes: 2 additions & 2 deletions JL.Core/Config/CoreConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void ApplyPreferences(SqliteConnection connection)
{
ankiConnectUriStr = ankiConnectUriStr
.Replace("://0.0.0.0:", "://127.0.0.1:", StringComparison.Ordinal)
.Replace("://localhost:", "://127.0.0.1:", StringComparison.Ordinal);
.Replace("://localhost:", "://127.0.0.1:", StringComparison.OrdinalIgnoreCase);

if (Uri.TryCreate(ankiConnectUriStr, UriKind.Absolute, out Uri? ankiConnectUri))
{
Expand All @@ -74,7 +74,7 @@ public void ApplyPreferences(SqliteConnection connection)
{
webSocketUriStr = webSocketUriStr
.Replace("://0.0.0.0:", "://127.0.0.1:", StringComparison.Ordinal)
.Replace("://localhost:", "://127.0.0.1:", StringComparison.Ordinal);
.Replace("://localhost:", "://127.0.0.1:", StringComparison.OrdinalIgnoreCase);

if (Uri.TryCreate(webSocketUriStr, UriKind.Absolute, out Uri? webSocketUri))
{
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,9 @@ public void ApplyPreferences(SqliteConnection connection)
{
searchUrlStr = searchUrlStr
.Replace("://0.0.0.0:", "://127.0.0.1:", StringComparison.Ordinal)
.Replace("://localhost", "://127.0.0.1", StringComparison.Ordinal);
.Replace("://localhost", "://127.0.0.1", StringComparison.OrdinalIgnoreCase);

if (Uri.IsWellFormedUriString(searchUrlStr.Replace("{SearchTerm}", "", StringComparison.Ordinal), UriKind.Absolute))
if (Uri.IsWellFormedUriString(searchUrlStr.Replace("{SearchTerm}", "", StringComparison.OrdinalIgnoreCase), UriKind.Absolute))
{
SearchUrl = searchUrlStr;
}
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/GUI/AddAudioSourceWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
case AudioSourceType.UrlJson:
uri = TextBlockUri.Text
.Replace("://0.0.0.0:", "://127.0.0.1:", StringComparison.Ordinal)
.Replace("://localhost", "://127.0.0.1", StringComparison.Ordinal);
.Replace("://localhost", "://127.0.0.1", StringComparison.OrdinalIgnoreCase);
if (string.IsNullOrEmpty(uri)
|| !Uri.IsWellFormedUriString(uri.Replace("{Term}", "", StringComparison.Ordinal).Replace("{Reading}", "", StringComparison.Ordinal), UriKind.Absolute)
|| !Uri.IsWellFormedUriString(uri.Replace("{Term}", "", StringComparison.OrdinalIgnoreCase).Replace("{Reading}", "", StringComparison.OrdinalIgnoreCase), UriKind.Absolute)
|| AudioUtils.AudioSources.ContainsKey(uri))
{
TextBlockUri.BorderBrush = Brushes.Red;
Expand Down
4 changes: 2 additions & 2 deletions JL.Windows/GUI/EditAudioSourceWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ private void SaveButton_Click(object sender, RoutedEventArgs e)
case AudioSourceType.UrlJson:
uri = TextBlockUri.Text
.Replace("://0.0.0.0:", "://127.0.0.1:", StringComparison.Ordinal)
.Replace("://localhost", "://127.0.0.1", StringComparison.Ordinal);
.Replace("://localhost", "://127.0.0.1", StringComparison.OrdinalIgnoreCase);
if (string.IsNullOrEmpty(uri)
|| !Uri.IsWellFormedUriString(uri.Replace("{Term}", "", StringComparison.Ordinal).Replace("{Reading}", "", StringComparison.Ordinal), UriKind.Absolute)
|| !Uri.IsWellFormedUriString(uri.Replace("{Term}", "", StringComparison.OrdinalIgnoreCase).Replace("{Reading}", "", StringComparison.OrdinalIgnoreCase), UriKind.Absolute)
|| (_uri != uri && AudioUtils.AudioSources.ContainsKey(uri)))
{
TextBlockUri.BorderBrush = Brushes.Red;
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/GUI/PreferencesWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ private void ApplyAnkiConnectUrlButton_Click(object sender, RoutedEventArgs e)
{
string normalizedUrl = AnkiUriTextBox.Text
.Replace("://0.0.0.0:", "://127.0.0.1:", StringComparison.Ordinal)
.Replace("://localhost:", "://127.0.0.1:", StringComparison.Ordinal);
.Replace("://localhost:", "://127.0.0.1:", StringComparison.OrdinalIgnoreCase);
CoreConfigManager.Instance.AnkiConnectUri = new Uri(normalizedUrl);
AnkiUriTextBox.Text = normalizedUrl;
}
Expand Down
2 changes: 1 addition & 1 deletion JL.Windows/Utilities/WindowsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public static void SearchWithBrowser(string? selectedText)
{
string urlToBeSearched = Uri.IsWellFormedUriString(selectedText, UriKind.Absolute)
? selectedText
: configManager.SearchUrl.Replace("{SearchTerm}", HttpUtility.UrlEncode(selectedText), StringComparison.Ordinal);
: configManager.SearchUrl.Replace("{SearchTerm}", HttpUtility.UrlEncode(selectedText), StringComparison.OrdinalIgnoreCase);

_ = Process.Start(new ProcessStartInfo("cmd",
$"/c start \"\" {browserPath} \"{urlToBeSearched}\"")
Expand Down

0 comments on commit c52a150

Please sign in to comment.