Skip to content

Commit

Permalink
Fix crash when resource not found
Browse files Browse the repository at this point in the history
  • Loading branch information
srwi committed Dec 19, 2020
1 parent 14e0bfa commit 2d33df2
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 22 deletions.
20 changes: 6 additions & 14 deletions EverythingToolbar/Helpers/ApplicationResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public void AddResource(ResourceDictionary resource)

public void AddResource(string path)
{
if (!File.Exists(path))
{
ToolbarLogger.GetLogger("EverythingToolbar").Error("Could not find resource file " + path);
return;
}

ResourceChanged?.Invoke(this, new ResourcesChangedEventArgs()
{
NewResource = new ResourceDictionary() { Source = new Uri(path) }
Expand All @@ -44,27 +50,13 @@ public void ApplyTheme(string themeName)
{
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string themePath = Path.Combine(assemblyFolder, "Themes", themeName + ".xaml");

if (!File.Exists(themePath))
{
ToolbarLogger.GetLogger("EverythingToolbar").Error("Theme file not found. Defaulting to 'Medium' theme.");
themePath = Path.Combine(assemblyFolder, "Themes", "Medium.xaml");
}

AddResource(themePath);
}

public void ApplyItemTemplate(string templateName)
{
string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string templatePath = Path.Combine(assemblyFolder, "ItemTemplates", templateName + ".xaml");

if (!File.Exists(templatePath))
{
ToolbarLogger.GetLogger("EverythingToolbar").Error("Item template file not found. Defaulting to 'Normal' template.");
templatePath = Path.Combine(assemblyFolder, "ItemTemplates", "Normal.xaml");
}

AddResource(templatePath);
}
}
Expand Down
2 changes: 1 addition & 1 deletion EverythingToolbar/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.2")]
[assembly: AssemblyVersion("0.6.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
4 changes: 2 additions & 2 deletions EverythingToolbar/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions EverythingToolbar/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
<Value Profile="(Default)">C:\\Program Files\\Everything\\Everything.exe</Value>
</Setting>
<Setting Name="theme" Type="System.String" Scope="User">
<Value Profile="(Default)" />
<Value Profile="(Default)">Medium</Value>
</Setting>
<Setting Name="itemTemplate" Type="System.String" Scope="User">
<Value Profile="(Default)" />
<Value Profile="(Default)">Normal</Value>
</Setting>
<Setting Name="isAutoApplyRules" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
Expand Down
3 changes: 3 additions & 0 deletions EverythingToolbar/Rules.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ private void CheckBox_Click(object sender, RoutedEventArgs e)

public static bool HandleRule(SearchResult searchResult, string command="")
{
if (searchResult == null)
return false;

if (Properties.Settings.Default.isAutoApplyRules && string.IsNullOrEmpty(command))
{
foreach (Rule r in LoadRules())
Expand Down
2 changes: 1 addition & 1 deletion EverythingToolbar/ToolbarControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ToolbarControl()
}
catch (Exception ex)
{
ToolbarLogger.GetLogger("EverythingToolbar").Error(ex, "Failed to apply resources.");
ToolbarLogger.GetLogger("EverythingToolbar").Error(ex, "Failed to apply resource.");
}
};
ApplicationResources.Instance.LoadDefaults();
Expand Down
4 changes: 2 additions & 2 deletions EverythingToolbar/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
<value>C:\\Program Files\\Everything\\Everything.exe</value>
</setting>
<setting name="theme" serializeAs="String">
<value />
<value>Medium</value>
</setting>
<setting name="itemTemplate" serializeAs="String">
<value />
<value>Normal</value>
</setting>
<setting name="isAutoApplyRules" serializeAs="String">
<value>False</value>
Expand Down

0 comments on commit 2d33df2

Please sign in to comment.