Skip to content

Commit

Permalink
Fixed crash if Chrome not detected since last version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonno12345 committed Jul 9, 2016
1 parent 580721c commit ce29a1b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 26 deletions.
14 changes: 14 additions & 0 deletions TileIconifier.Core/Custom/Builder/ChromeCustomShortcutBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,26 @@

#endregion

using System;
using System.IO;

namespace TileIconifier.Core.Custom.Builder
{
public class ChromeCustomShortcutBuilder : BaseCustomShortcutBuilder
{
public ChromeCustomShortcutBuilder(GenerateCustomShortcutParams generateParameters) : base(generateParameters)
{

}

public override CustomShortcut GenerateCustomShortcut(string shortcutName)
{
if (!File.Exists(Parameters.ShortcutTarget))
{
throw new FileNotFoundException(Parameters.ShortcutTarget);
}

return base.GenerateCustomShortcut(shortcutName);
}

protected override CustomShortcutType ShortcutType { get; } = CustomShortcutType.ChromeApp;
Expand Down
24 changes: 21 additions & 3 deletions TileIconifier.Core/Custom/Chrome/ChromeAppLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,30 @@ var defaultChromeInstallationPath in
throw new FileNotFoundException();
}

public static List<ChromeApp> GetChromeAppItems()
public static bool ChromeInstallationPathExists()
{
if (!Directory.Exists(AppLibraryPath))
throw new DirectoryNotFoundException(AppLibraryPath);
try
{
return File.Exists(ChromeInstallationPath);
}
catch
{
return false;
}
}

public static bool ChromeAppLibraryPathExists()
{
return Directory.Exists(AppLibraryPath);
}

public static List<ChromeApp> GetChromeAppItems()
{
var returnList = new List<ChromeApp>();
if (!ChromeAppLibraryPathExists())
{
return returnList;
}
//loop through all extension app Id folders
foreach (var directory in new DirectoryInfo(AppLibraryPath).GetDirectories())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,24 @@ public static List<ChromeAppListViewItem> ChromeAppListViewItems

public static void RefreshList(bool force = false)
{
if (force || !_chromeAppListViewItems.Any())
_chromeAppListViewItems = ChromeAppLibrary.GetChromeAppItems().Select(c => new ChromeAppListViewItem(c))
.ToList();
try
{
if (!ChromeAppLibrary.ChromeAppLibraryPathExists() || !ChromeAppLibrary.ChromeInstallationPathExists())
{
return;
}

if (force || !_chromeAppListViewItems.Any())
{
_chromeAppListViewItems =
ChromeAppLibrary.GetChromeAppItems().Select(c => new ChromeAppListViewItem(c))
.ToList();
}
}
catch
{
//ignore
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,24 @@ private void GenerateShortcut(BaseCustomShortcutBuilder baseCustomShortcutBuilde
return;
}

var customShortcut = baseCustomShortcutBuilder.GenerateCustomShortcut(shortcutName);
try
{
var customShortcut = baseCustomShortcutBuilder.GenerateCustomShortcut(shortcutName);

BuildIconifiedTile(ImageUtils.ImageToByteArray(pctCurrentIcon.Image), customShortcut);
BuildIconifiedTile(ImageUtils.ImageToByteArray(pctCurrentIcon.Image), customShortcut);

//confirm to the user the shortcut has been created
ConfirmToUser(shortcutName);
//confirm to the user the shortcut has been created
ConfirmToUser(shortcutName);
}
catch (FileNotFoundException ex)
{
MessageBox.Show(ex.Message, Strings.FileCouldNotBeFound,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
catch (Exception ex)
{
FrmException.ShowExceptionHandler(ex);
}
}

private GenerateCustomShortcutParams GenerateParams(string shortcutTarget, string shortcutArguments,
Expand Down Expand Up @@ -521,26 +533,16 @@ private void SetUpChrome()

private void PopulateGoogleAppLibraryPath()
{
try
{
txtChromeAppPath.Text = ChromeAppLibrary.AppLibraryPath;
}
catch (Exception ex)
{
txtChromeAppPath.Text = ex.Message;
}
txtChromeAppPath.Text = ChromeAppLibrary.ChromeAppLibraryPathExists()
? ChromeAppLibrary.AppLibraryPath
: $"Path not found: {ChromeAppLibrary.AppLibraryPath}";
}

private void PopulateChromeInstallationPath()
{
try
{
txtChromeExePath.Text = ChromeAppLibrary.ChromeInstallationPath;
}
catch
{
txtChromeExePath.Text = Strings.UnableToFindChromeInstallationPath;
}
txtChromeExePath.Text = ChromeAppLibrary.ChromeInstallationPathExists()
? ChromeAppLibrary.ChromeInstallationPath
: Strings.UnableToFindChromeInstallationPath;
}

private void SetUpChromeListView()
Expand Down

0 comments on commit ce29a1b

Please sign in to comment.