1
- namespace Flow . Launcher . Plugin . WebSearch
1
+ using Flow . Launcher . Infrastructure ;
2
+ using Flow . Launcher . Infrastructure . UserSettings ;
3
+ using System ;
4
+ using System . IO ;
5
+ using System . Windows . Forms ;
6
+
7
+ namespace Flow . Launcher . Plugin . WebSearch
2
8
{
3
9
public class SearchSourceViewModel
4
10
{
11
+ private readonly string destinationDirectory =
12
+ Path . Combine ( DataLocation . DataDirectory ( ) , @"Settings\Plugins\Flow.Launcher.Plugin.WebSearch\IconImages" ) ;
13
+
5
14
public SearchSource SearchSource { get ; set ; }
15
+
16
+ public void UpdateIconPath ( SearchSource selectedSearchSource , string fullpathToSelectedImage )
17
+ {
18
+ var iconFileName = Path . GetFileName ( fullpathToSelectedImage ) ;
19
+ selectedSearchSource . Icon = iconFileName ;
20
+ selectedSearchSource . IconPath = Path . Combine ( destinationDirectory , Path . GetFileName ( fullpathToSelectedImage ) ) ;
21
+ }
22
+
23
+ public void CopyNewImageToUserDataDirectory ( SearchSource selectedSearchSource , string fullpathToSelectedImage , string fullPathToOriginalImage )
24
+ {
25
+ var destinationFileNameFullPath = Path . Combine ( destinationDirectory , Path . GetFileName ( fullpathToSelectedImage ) ) ;
26
+
27
+ try
28
+ {
29
+ if ( ! Directory . Exists ( destinationDirectory ) )
30
+ Directory . CreateDirectory ( destinationDirectory ) ;
31
+
32
+ File . Copy ( fullpathToSelectedImage , destinationFileNameFullPath ) ;
33
+ }
34
+ catch ( Exception e )
35
+ {
36
+ #if DEBUG
37
+ throw e ;
38
+ #else
39
+ MessageBox . Show ( string . Format ( "Copying the selected image file to {0} has failed, changes will now be reverted" , destinationFileNameFullPath ) ) ;
40
+ UpdateIconPath ( selectedSearchSource , fullPathToOriginalImage ) ;
41
+ #endif
42
+ }
43
+
44
+ }
45
+
46
+ public bool ImageFileExistsInLocation ( string fullpathToSelectedImage )
47
+ {
48
+ var fileName = Path . GetFileName ( fullpathToSelectedImage ) ;
49
+
50
+ var newImageFilePathToBe = Path . Combine ( destinationDirectory , fileName ) ;
51
+
52
+ return File . Exists ( newImageFilePathToBe ) ;
53
+ }
6
54
}
7
55
}
0 commit comments