3
3
using System ;
4
4
using System . Collections . Generic ;
5
5
using System . Diagnostics ;
6
+ using System . Drawing ;
7
+ using System . Drawing . Imaging ;
6
8
using System . Linq ;
7
9
using System . Reflection ;
10
+ using System . Runtime . InteropServices ;
11
+ using System . Windows ;
12
+ using System . Windows . Media . Imaging ;
8
13
9
14
namespace AutoHDR
10
15
{
@@ -17,84 +22,117 @@ enum ShowWindowEnum
17
22
Restore = 9 , ShowDefault = 10 , ForceMinimized = 11
18
23
} ;
19
24
20
- public static class Tools
21
- {
22
-
23
- public static int GlobalRefreshInterval = 500 ;
24
-
25
- public static void SetAutoStart ( string applicationName , string filePath , bool autostart )
26
- {
27
- RegistryKey rk = Microsoft . Win32 . Registry . CurrentUser . OpenSubKey ( @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run" , true ) ;
28
- object existing = rk . GetValue ( applicationName ) ;
29
- if ( filePath . Equals ( existing ) && autostart )
30
- return ;
31
- if ( rk . GetValue ( applicationName ) == null && ! autostart )
32
- return ;
33
-
34
- if ( autostart )
35
- rk . SetValue ( applicationName , filePath ) ;
36
- else
37
- rk . DeleteValue ( applicationName , false ) ;
38
- }
39
-
40
- public static IDictionary < TKey , TValue > CloneDictionaryCloningValues < TKey , TValue >
41
- ( Dictionary < TKey , TValue > original ) where TValue : ICloneable
42
- {
43
- Dictionary < TKey , TValue > ret = new Dictionary < TKey , TValue > ( original . Count , original . Comparer ) ;
44
- foreach ( KeyValuePair < TKey , TValue > entry in original )
45
- {
46
- ret . Add ( entry . Key , ( TValue ) entry . Value . Clone ( ) ) ;
47
- }
48
- return ret ;
49
- }
50
- public static Version ApplicationVersion
51
- {
52
- get
53
- {
54
- System . Reflection . Assembly assembly = System . Reflection . Assembly . GetExecutingAssembly ( ) ;
55
- string versionString = assembly . GetName ( ) . Version . ToString ( ) ;
56
- Version version = new Version ( versionString . Substring ( 0 , versionString . LastIndexOf ( '.' ) ) ) ;
57
- return version ;
58
- }
59
- }
60
-
61
- public static Logs Logs = new Logs ( $ "{ System . AppDomain . CurrentDomain . BaseDirectory } AutoHDR.log", "AutoHDR" , Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version . ToString ( ) , false ) ;
62
-
63
- [ System . Runtime . InteropServices . DllImport ( "user32.dll" ) ]
64
- [ return : System . Runtime . InteropServices . MarshalAs ( System . Runtime . InteropServices . UnmanagedType . Bool ) ]
65
- private static extern bool ShowWindow ( IntPtr hWnd , ShowWindowEnum flags ) ;
66
-
67
- [ System . Runtime . InteropServices . DllImport ( "user32.dll" ) ]
68
- private static extern int SetForegroundWindow ( IntPtr hwnd ) ;
69
-
70
-
71
- public static void BringMainWindowToFront ( string processName )
72
- {
73
- // get the process
74
- Process bProcess = Process . GetProcessesByName ( processName ) . FirstOrDefault ( ) ;
75
-
76
- // check if the process is running
77
- if ( bProcess != null )
78
- {
79
- // check if the window is hidden / minimized
80
- if ( bProcess . MainWindowHandle == IntPtr . Zero )
81
- {
82
- // the window is hidden so try to restore it before setting focus.
83
- ShowWindow ( bProcess . Handle , ShowWindowEnum . Restore ) ;
84
- }
85
-
86
- // set user the focus to the window
87
- SetForegroundWindow ( bProcess . MainWindowHandle ) ;
88
- }
89
- else
90
- {
91
- // the process is not running, so start it
92
- Process . Start ( processName ) ;
93
- }
94
- }
95
-
96
- }
97
-
25
+ public static class Tools
26
+ {
27
+
28
+ public static int GlobalRefreshInterval = 500 ;
29
+
30
+ public static void SetAutoStart ( string applicationName , string filePath , bool autostart )
31
+ {
32
+ RegistryKey rk = Microsoft . Win32 . Registry . CurrentUser . OpenSubKey ( @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run" , true ) ;
33
+ object existing = rk . GetValue ( applicationName ) ;
34
+ if ( filePath . Equals ( existing ) && autostart )
35
+ return ;
36
+ if ( rk . GetValue ( applicationName ) == null && ! autostart )
37
+ return ;
38
+
39
+ if ( autostart )
40
+ rk . SetValue ( applicationName , filePath ) ;
41
+ else
42
+ rk . DeleteValue ( applicationName , false ) ;
43
+ }
44
+
45
+ public static IDictionary < TKey , TValue > CloneDictionaryCloningValues < TKey , TValue >
46
+ ( Dictionary < TKey , TValue > original ) where TValue : ICloneable
47
+ {
48
+ Dictionary < TKey , TValue > ret = new Dictionary < TKey , TValue > ( original . Count , original . Comparer ) ;
49
+ foreach ( KeyValuePair < TKey , TValue > entry in original )
50
+ {
51
+ ret . Add ( entry . Key , ( TValue ) entry . Value . Clone ( ) ) ;
52
+ }
53
+ return ret ;
54
+ }
55
+ public static Version ApplicationVersion
56
+ {
57
+ get
58
+ {
59
+ System . Reflection . Assembly assembly = System . Reflection . Assembly . GetExecutingAssembly ( ) ;
60
+ string versionString = assembly . GetName ( ) . Version . ToString ( ) ;
61
+ Version version = new Version ( versionString . Substring ( 0 , versionString . LastIndexOf ( '.' ) ) ) ;
62
+ return version ;
63
+ }
64
+ }
65
+
66
+ public static Logs Logs = new Logs ( $ "{ System . AppDomain . CurrentDomain . BaseDirectory } AutoHDR.log", "AutoHDR" , Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version . ToString ( ) , false ) ;
67
+
68
+ [ System . Runtime . InteropServices . DllImport ( "user32.dll" ) ]
69
+ [ return : System . Runtime . InteropServices . MarshalAs ( System . Runtime . InteropServices . UnmanagedType . Bool ) ]
70
+ private static extern bool ShowWindow ( IntPtr hWnd , ShowWindowEnum flags ) ;
71
+
72
+ [ System . Runtime . InteropServices . DllImport ( "user32.dll" ) ]
73
+ private static extern int SetForegroundWindow ( IntPtr hwnd ) ;
74
+
75
+
76
+ public static void BringMainWindowToFront ( string processName )
77
+ {
78
+ // get the process
79
+ Process bProcess = Process . GetProcessesByName ( processName ) . FirstOrDefault ( ) ;
80
+
81
+ // check if the process is running
82
+ if ( bProcess != null )
83
+ {
84
+ // check if the window is hidden / minimized
85
+ if ( bProcess . MainWindowHandle == IntPtr . Zero )
86
+ {
87
+ // the window is hidden so try to restore it before setting focus.
88
+ ShowWindow ( bProcess . Handle , ShowWindowEnum . Restore ) ;
89
+ }
90
+
91
+ // set user the focus to the window
92
+ SetForegroundWindow ( bProcess . MainWindowHandle ) ;
93
+ }
94
+ else
95
+ {
96
+ // the process is not running, so start it
97
+ Process . Start ( processName ) ;
98
+ }
99
+ }
100
+
101
+
102
+
103
+
104
+ /// <summary>
105
+ /// Returns an icon for a given file - indicated by the name parameter.
106
+ /// </summary>
107
+ /// <param name="name">Pathname for file.</param>
108
+ /// <param name="size">Large or small</param>
109
+ /// <param name="linkOverlay">Whether to include the link icon</param>
110
+ /// <returns>System.Drawing.Icon</returns>
111
+ public static Bitmap GetFileIcon ( string name )
112
+ {
113
+ return CodectoryCore . Windows . Icons . IconHelper . GetIconImage ( name , CodectoryCore . Windows . Icons . IconHelper . IconSize . jumbo ) ;
114
+ }
115
+
116
+ private static Bitmap GetBitmap ( BitmapSource source )
117
+ {
118
+ Bitmap bmp = new Bitmap (
119
+ source . PixelWidth ,
120
+ source . PixelHeight ,
121
+ PixelFormat . Format32bppPArgb ) ;
122
+ BitmapData data = bmp . LockBits (
123
+ new Rectangle ( System . Drawing . Point . Empty , bmp . Size ) ,
124
+ ImageLockMode . WriteOnly ,
125
+ PixelFormat . Format32bppPArgb ) ;
126
+ source . CopyPixels (
127
+ Int32Rect . Empty ,
128
+ data . Scan0 ,
129
+ data . Height * data . Stride ,
130
+ data . Stride ) ;
131
+ bmp . UnlockBits ( data ) ;
132
+ return bmp ;
133
+ }
134
+
135
+ }
98
136
99
137
}
100
138
0 commit comments