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