2020-08-11 22:23:10 +00:00
|
|
|
using Flow.Launcher.Infrastructure.Image;
|
2020-07-21 22:18:36 +00:00
|
|
|
using System;
|
2020-08-11 22:23:10 +00:00
|
|
|
using System.Drawing;
|
2020-07-21 22:18:36 +00:00
|
|
|
using System.IO;
|
2020-08-11 22:23:10 +00:00
|
|
|
using System.Windows.Media;
|
2020-07-21 22:18:36 +00:00
|
|
|
|
|
|
|
|
namespace Flow.Launcher.Plugin.WebSearch
|
2016-06-20 23:14:32 +00:00
|
|
|
{
|
2020-07-22 10:35:56 +00:00
|
|
|
public class SearchSourceViewModel : BaseModel
|
2016-06-20 23:14:32 +00:00
|
|
|
{
|
|
|
|
|
public SearchSource SearchSource { get; set; }
|
2020-07-21 22:18:36 +00:00
|
|
|
|
2020-08-11 21:12:43 +00:00
|
|
|
public void UpdateIconAttributes(SearchSource selectedSearchSource, string fullpathToSelectedImage)
|
2020-07-21 22:18:36 +00:00
|
|
|
{
|
2020-07-22 12:00:14 +00:00
|
|
|
var parentDirectorySelectedImg = Directory.GetParent(fullpathToSelectedImage).ToString();
|
|
|
|
|
|
2020-08-11 21:08:24 +00:00
|
|
|
selectedSearchSource.CustomIcon = parentDirectorySelectedImg != Main.DefaultImagesDirectory;
|
2020-07-22 12:00:14 +00:00
|
|
|
|
2020-07-21 22:18:36 +00:00
|
|
|
var iconFileName = Path.GetFileName(fullpathToSelectedImage);
|
|
|
|
|
selectedSearchSource.Icon = iconFileName;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-22 12:00:14 +00:00
|
|
|
public void CopyNewImageToUserDataDirectoryIfRequired(
|
|
|
|
|
SearchSource selectedSearchSource, string fullpathToSelectedImage, string fullPathToOriginalImage)
|
2020-07-21 22:18:36 +00:00
|
|
|
{
|
2020-08-11 21:08:24 +00:00
|
|
|
var destinationFileNameFullPath = Path.Combine(Main.CustomImagesDirectory, Path.GetFileName(fullpathToSelectedImage));
|
2020-07-21 22:18:36 +00:00
|
|
|
|
2020-07-22 12:00:14 +00:00
|
|
|
var parentDirectorySelectedImg = Directory.GetParent(fullpathToSelectedImage).ToString();
|
2020-07-22 10:35:56 +00:00
|
|
|
|
2020-08-11 21:08:24 +00:00
|
|
|
if (parentDirectorySelectedImg != Main.CustomImagesDirectory && parentDirectorySelectedImg != Main.DefaultImagesDirectory)
|
2020-07-21 22:18:36 +00:00
|
|
|
{
|
2020-07-22 12:00:14 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
File.Copy(fullpathToSelectedImage, destinationFileNameFullPath);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2020-07-21 22:18:36 +00:00
|
|
|
#if DEBUG
|
2020-07-22 12:00:14 +00:00
|
|
|
throw e;
|
2020-07-21 22:18:36 +00:00
|
|
|
#else
|
|
|
|
|
MessageBox.Show(string.Format("Copying the selected image file to {0} has failed, changes will now be reverted", destinationFileNameFullPath));
|
|
|
|
|
UpdateIconPath(selectedSearchSource, fullPathToOriginalImage);
|
|
|
|
|
#endif
|
2020-07-22 12:00:14 +00:00
|
|
|
}
|
2020-07-21 22:18:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-22 12:00:14 +00:00
|
|
|
internal void SetupCustomImagesDirectory()
|
2020-07-21 22:18:36 +00:00
|
|
|
{
|
2020-08-11 21:08:24 +00:00
|
|
|
if (!Directory.Exists(Main.CustomImagesDirectory))
|
|
|
|
|
Directory.CreateDirectory(Main.CustomImagesDirectory);
|
2020-07-22 12:00:14 +00:00
|
|
|
}
|
2020-07-21 22:18:36 +00:00
|
|
|
|
2020-07-22 12:00:14 +00:00
|
|
|
internal bool ShouldProvideHint(string fullPathToSelectedImage)
|
|
|
|
|
{
|
2020-08-11 21:08:24 +00:00
|
|
|
return Directory.GetParent(fullPathToSelectedImage).ToString() == Main.DefaultImagesDirectory;
|
2020-07-21 22:18:36 +00:00
|
|
|
}
|
2020-08-11 22:23:10 +00:00
|
|
|
|
|
|
|
|
internal ImageSource LoadPreviewIcon(string pathToPreviewIconImage)
|
|
|
|
|
{
|
|
|
|
|
return ImageLoader.Load(pathToPreviewIconImage);
|
|
|
|
|
}
|
2016-06-20 23:14:32 +00:00
|
|
|
}
|
2016-06-20 23:18:35 +00:00
|
|
|
}
|