Skip to content

Commit

Permalink
added try catch to handle exceptions at mainWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
DineshSolanki committed Aug 5, 2021
1 parent 38e0e30 commit 317aacf
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 87 deletions.
8 changes: 1 addition & 7 deletions FoliCon/Models/BackdropSize.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoliCon.Models
namespace FoliCon.Models
{
public static class BackdropSize
{
Expand Down
8 changes: 1 addition & 7 deletions FoliCon/Models/Languages.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoliCon.Models
namespace FoliCon.Models
{
public enum Languages
{
Expand Down
8 changes: 1 addition & 7 deletions FoliCon/Models/PosterSize.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FoliCon.Models
namespace FoliCon.Models
{
public static class PosterSize
{
Expand Down
1 change: 1 addition & 0 deletions FoliCon/Modules/TMDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public static ObservableCollection<ListItem> ExtractTvDetailsIntoListItem(Search
/// <param name="result">Search Response</param>
/// <param name="resultType">Type of search Response.</param>
/// <param name="fullFolderPath">Full Path to the current Media Folder</param>
/// <param name="rating">Rating for media</param>
/// TODO: Merge parameter response and resultType.
public void ResultPicked(dynamic result, string resultType, string fullFolderPath, string rating = "")
{
Expand Down
34 changes: 34 additions & 0 deletions FoliCon/Modules/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,5 +531,39 @@ public static void WriteApiConfiguration(string tmdbkey, string igdbClientId, st
settings.DevClientSecret = dartClientSecret;
settings.Save();
}

public static CultureInfo GetCultureInfoByLanguage(Languages language)
{
CultureInfo cultureInfo;
switch (language)
{
case Languages.English:
ConfigHelper.Instance.SetLang("en");
cultureInfo = new CultureInfo("en-US");
break;
case Languages.Spanish:
ConfigHelper.Instance.SetLang("es");
cultureInfo = new CultureInfo("es-MX");
break;
case Languages.Arabic:
ConfigHelper.Instance.SetLang("ar");
cultureInfo = new CultureInfo("ar-SA");
break;
case Languages.Russian:
ConfigHelper.Instance.SetLang("ru");
cultureInfo = new CultureInfo("ru-RU");
break;
case Languages.Hindi:
ConfigHelper.Instance.SetLang("hi");
cultureInfo = new CultureInfo("hi-IN");
break;
default:
ConfigHelper.Instance.SetLang("en");
cultureInfo = new CultureInfo("en-US");
break;
}

return cultureInfo;
}
}
}
75 changes: 43 additions & 32 deletions FoliCon/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Globalization;
using System.IO;
using System.Net.NetworkInformation;
using System.Threading;
using HandyControl.Tools.Extension;

namespace FoliCon.ViewModels
Expand Down Expand Up @@ -228,52 +230,61 @@ private void LoadMethod()

private async void SearchAndMakeMethod()
{
if (Directory.Exists(SelectedFolder))
{
Fnames = Util.GetFolderNames(SelectedFolder);
}
else
try
{
MessageBox.Show(CustomMessageBox.Error(LangProvider.GetLang("FolderDoesNotExist"), LangProvider.GetLang("InvalidPath")));
return;
}
if (Directory.Exists(SelectedFolder))
{
Fnames = Util.GetFolderNames(SelectedFolder);
}
else
{
MessageBox.Show(CustomMessageBox.Error(LangProvider.GetLang("FolderDoesNotExist"), LangProvider.GetLang("InvalidPath")));
return;
}

if (Fnames.Count != 0)
{
if (Util.IsNetworkAvailable())
if (Fnames.Count != 0)
{
if (!IsObjectsInitialized)
if (Util.IsNetworkAvailable())
{
InitializeClientObjects();
IsObjectsInitialized = true;
}
if (!IsObjectsInitialized)
{
InitializeClientObjects();
IsObjectsInitialized = true;
}

StatusBarProperties.ResetData();
FinalListViewData.Data.Clear();
StatusBarProperties.TotalFolders = Fnames.Count;
PrepareForSearch();
if (IconMode == "Poster")
await ProcessPosterModeAsync();
StatusBarProperties.ResetData();
FinalListViewData.Data.Clear();
StatusBarProperties.TotalFolders = Fnames.Count;
PrepareForSearch();
if (IconMode == "Poster")
await ProcessPosterModeAsync();
else
{
ProcessProfessionalMode();
}
StatusBarProperties.TotalIcons = BusyIndicatorProperties.Max =
StatusBarProperties.ProgressBarData.Max = _imgDownloadList.Count;
BusyIndicatorProperties.Text = LangProvider.GetLang("DownloadingIconWithCount").Format(1, _imgDownloadList.Count);
if (_imgDownloadList.Count > 0)
await StartDownloadingAsync();
else
IsMakeEnabled = true;
}
else
{
ProcessProfessionalMode();
MessageBox.Show(CustomMessageBox.Error(LangProvider.GetLang("NoInternet"), LangProvider.GetLang("NetworkError")));
}
StatusBarProperties.TotalIcons = BusyIndicatorProperties.Max =
StatusBarProperties.ProgressBarData.Max = _imgDownloadList.Count;
BusyIndicatorProperties.Text = LangProvider.GetLang("DownloadingIconWithCount").Format(1, _imgDownloadList.Count);
if (_imgDownloadList.Count > 0)
await StartDownloadingAsync();
else
IsMakeEnabled = true;
}
else
{
MessageBox.Show(CustomMessageBox.Error(LangProvider.GetLang("NoInternet"), LangProvider.GetLang("NetworkError")));
MessageBox.Show(CustomMessageBox.Warning(LangProvider.GetLang("IconsAlready"), LangProvider.GetLang("FolderError")));
}
}
else
catch (Exception e)
{
MessageBox.Show(CustomMessageBox.Warning(LangProvider.GetLang("IconsAlready"), LangProvider.GetLang("FolderError")));
MessageBox.Show(CustomMessageBox.Error(e.Message, "Exception Occurred"));
StatusBarProperties.ResetData();
IsMakeEnabled = true;
}
}

Expand Down
2 changes: 0 additions & 2 deletions FoliCon/ViewModels/PosterPickerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using FoliCon.Properties.Langs;
using TMDbLib.Objects.General;
using TMDbLib.Objects.Search;
Expand Down
3 changes: 1 addition & 2 deletions FoliCon/ViewModels/ProSearchResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,11 @@ private async void PrepareForSearch()

private async Task Search(string query, int offset = 0)
{
int lastIndex;
Index = 0;
while (true)
{
var searchResult = await DArtObject.Browse(query, offset);
lastIndex = Index;
var lastIndex = Index;
if (searchResult.Results?.Length > 0)
{
TotalPosters = searchResult.Results.Length + offset;
Expand Down
1 change: 0 additions & 1 deletion FoliCon/ViewModels/SearchResultViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Input;
Expand Down
33 changes: 4 additions & 29 deletions FoliCon/Views/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,10 @@ private void CmbLanguage_OnSelectionChanged(object sender, SelectionChangedEvent
if (CmbLanguage.SelectedItem is null)
return;
var selectedLanguage = (Languages)CmbLanguage.SelectedValue;
switch (selectedLanguage)
{
case Languages.English:
ConfigHelper.Instance.SetLang("en");
LangProvider.Culture = new CultureInfo("en-US");
break;
case Languages.Spanish:
ConfigHelper.Instance.SetLang("es");
LangProvider.Culture = new CultureInfo("es-MX");
break;
case Languages.Arabic:
ConfigHelper.Instance.SetLang("ar");
LangProvider.Culture = new CultureInfo("ar-SA");
break;
case Languages.Russian:
ConfigHelper.Instance.SetLang("ru");
LangProvider.Culture = new CultureInfo("ru-RU");
break;
case Languages.Hindi:
ConfigHelper.Instance.SetLang("hi");
LangProvider.Culture = new CultureInfo("hi-IN");
break;
default:
ConfigHelper.Instance.SetLang("en");
LangProvider.Culture = new CultureInfo("en-US");
break;
}
Thread.CurrentThread.CurrentCulture = LangProvider.Culture;
Thread.CurrentThread.CurrentUICulture = LangProvider.Culture;
var cultureInfo = Util.GetCultureInfoByLanguage(selectedLanguage);
LangProvider.Culture = cultureInfo;
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Kernel32.SetThreadUILanguage((ushort)Thread.CurrentThread.CurrentUICulture.LCID);
if (FinalList is not null)
{
Expand Down

0 comments on commit 317aacf

Please sign in to comment.