mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
55 lines
No EOL
2 KiB
C#
55 lines
No EOL
2 KiB
C#
using Flow.Launcher.Infrastructure;
|
|
using Flow.Launcher.Infrastructure.UserSettings;
|
|
using System;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Flow.Launcher.Plugin.WebSearch
|
|
{
|
|
public class SearchSourceViewModel
|
|
{
|
|
private readonly string destinationDirectory =
|
|
Path.Combine(DataLocation.DataDirectory(), @"Settings\Plugins\Flow.Launcher.Plugin.WebSearch\IconImages");
|
|
|
|
public SearchSource SearchSource { get; set; }
|
|
|
|
public void UpdateIconPath(SearchSource selectedSearchSource, string fullpathToSelectedImage)
|
|
{
|
|
var iconFileName = Path.GetFileName(fullpathToSelectedImage);
|
|
selectedSearchSource.Icon = iconFileName;
|
|
selectedSearchSource.IconPath = Path.Combine(destinationDirectory, Path.GetFileName(fullpathToSelectedImage));
|
|
}
|
|
|
|
public void CopyNewImageToUserDataDirectory(SearchSource selectedSearchSource, string fullpathToSelectedImage, string fullPathToOriginalImage)
|
|
{
|
|
var destinationFileNameFullPath = Path.Combine(destinationDirectory, Path.GetFileName(fullpathToSelectedImage));
|
|
|
|
try
|
|
{
|
|
if (!Directory.Exists(destinationDirectory))
|
|
Directory.CreateDirectory(destinationDirectory);
|
|
|
|
File.Copy(fullpathToSelectedImage, destinationFileNameFullPath);
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
#if DEBUG
|
|
throw e;
|
|
#else
|
|
MessageBox.Show(string.Format("Copying the selected image file to {0} has failed, changes will now be reverted", destinationFileNameFullPath));
|
|
UpdateIconPath(selectedSearchSource, fullPathToOriginalImage);
|
|
#endif
|
|
}
|
|
|
|
}
|
|
|
|
public bool ImageFileExistsInLocation(string fullpathToSelectedImage)
|
|
{
|
|
var fileName = Path.GetFileName(fullpathToSelectedImage);
|
|
|
|
var newImageFilePathToBe = Path.Combine(destinationDirectory, fileName);
|
|
|
|
return File.Exists(newImageFilePathToBe);
|
|
}
|
|
}
|
|
} |