1- using Microsoft . Win32 ;
1+ using Cursor_Installer_Creator . Data ;
2+ using Microsoft . Win32 ;
23using System ;
34using System . Collections . Generic ;
45using System . Diagnostics ;
1112using System . Text ;
1213using Cursor = System . Windows . Forms . Cursor ;
1314
14- namespace Cursor_Installer_Creator ;
15+ namespace Cursor_Installer_Creator . Utils ;
1516
1617public static class CursorHelper
1718{
@@ -28,19 +29,17 @@ public static List<CCursor> GetSelectedCursors()
2829 foreach ( var valueName in valueNames )
2930 {
3031 var cursorPath = key . GetValue ( valueName ) ? . ToString ( ) ;
31- if ( string . IsNullOrEmpty ( cursorPath ) || ! File . Exists ( cursorPath ) )
32+ if ( string . IsNullOrWhiteSpace ( cursorPath ) || ! File . Exists ( cursorPath ) )
3233 {
3334 var assignment = CursorAssignment . FromName ( valueName , CursorAssignmentType . WindowsReg ) ;
34- cursorPath = $ "C:/ Windows/ Cursors/ { assignment ? . Windows } .cur";
35+ cursorPath = @ $ "C:\ Windows\ Cursors\ { assignment ? . Windows } .cur";
3536 }
3637
3738 if ( File . Exists ( cursorPath ) )
3839 {
3940 var ccursor = ConvertCursorFile ( cursorPath , valueName ) ;
4041 if ( ccursor is not null )
41- {
4242 ccursors . Add ( ccursor ) ;
43- }
4443 }
4544 }
4645 }
@@ -58,9 +57,7 @@ public static List<CCursor> GetSelectedCursors()
5857 } ;
5958 ccursor . CursorPath = ConvertCursorFile ( ccursor . CursorPath , ccursor . Assignment ) ? . CursorPath ?? ccursor . CursorPath ;
6059 if ( File . Exists ( ccursor . CursorPath ) )
61- {
6260 ccursors . Add ( ccursor ) ;
63- }
6461 }
6562 }
6663
@@ -74,9 +71,7 @@ public static List<CCursor> GetSelectedCursors()
7471 {
7572 var cursorPath = key . GetValue ( assignment . WindowsReg ) ? . ToString ( ) ;
7673 if ( ! File . Exists ( cursorPath ) )
77- {
7874 cursorPath = @$ "C:\Windows\Cursors\{ assignment . Windows } .cur";
79- }
8075
8176 return ConvertCursorFile ( cursorPath , assignment . ID ) ;
8277 }
@@ -108,9 +103,7 @@ private static Dictionary<string, string> ParseInstallerInfStrings(string filePa
108103 var value = parts [ 1 ] . Trim ( ) . TrimStart ( '\" ' ) . TrimEnd ( '\" ' ) ;
109104 var assignment = CursorAssignment . FromName ( key , CursorAssignmentType . WindowsInstall ) ;
110105 if ( assignment is not null )
111- {
112106 stringsDictionary [ assignment . WindowsReg ] = value ;
113- }
114107 }
115108 }
116109 }
@@ -129,9 +122,7 @@ public static IEnumerable<CCursor> CursorsFromInstallerInf(string filePath)
129122 {
130123 var ccursor = ConvertCursorFile ( Path . Combine ( Path . GetDirectoryName ( filePath ) ! , kvp . Value ) , assignment ) ;
131124 if ( ccursor is not null )
132- {
133125 ccursors . Add ( ccursor ) ;
134- }
135126 }
136127 }
137128 return ccursors ;
@@ -163,9 +154,7 @@ public static void RemoveCursorDisplayImage(CCursor ccursor)
163154 {
164155 var prevCursorImagePath = Path . ChangeExtension ( ccursor . CursorPath , ".png" ) ;
165156 if ( File . Exists ( prevCursorImagePath ) )
166- {
167157 File . Delete ( prevCursorImagePath ) ;
168- }
169158 }
170159
171160 public static CCursor ? ConvertCursorFile ( string cursorPath , int cursorID ) => ConvertCursorFile ( cursorPath , CursorAssignment . CursorAssignments [ cursorID ] ) ;
@@ -188,9 +177,7 @@ public static void RemoveCursorDisplayImage(CCursor ccursor)
188177
189178 var prevCursorImagePath = Path . ChangeExtension ( destinationFullPath , ".png" ) ;
190179 if ( File . Exists ( prevCursorImagePath ) )
191- {
192180 File . Delete ( prevCursorImagePath ) ;
193- }
194181
195182 var ccursor = new CCursor
196183 {
@@ -207,24 +194,24 @@ public static void RemoveCursorDisplayImage(CCursor ccursor)
207194 }
208195
209196 [ DllImport ( "User32.dll" , CharSet = CharSet . Unicode ) ]
210- private static extern IntPtr LoadCursorFromFile ( string str ) ;
197+ private static extern nint LoadCursorFromFile ( string str ) ;
211198 private static Cursor GetCursorFromFile ( string filename )
212199 {
213200 var hCursor = LoadCursorFromFile ( filename ) ;
214- return ! IntPtr . Zero . Equals ( hCursor )
201+ return ! nint . Zero . Equals ( hCursor )
215202 ? new Cursor ( hCursor )
216203 : throw new ApplicationException ( "Could not create cursor from file " + filename ) ;
217204 }
218205
219206 public static void CreateInstaller ( string packageName , string folderPath , IEnumerable < CCursor > ccursors , bool createZip = true )
220207 {
221- using ( var writer = new StreamWriter ( $ "{ Program . TempPath } / installer.inf") )
208+ using ( var writer = new StreamWriter ( @ $ "{ Program . TempPath } \ installer.inf") )
222209 {
223210 writer . Write ( CreateInstallerInfString ( packageName , ccursors ) ) ;
224211 }
225212
226213 var files = ccursors . Select ( x => x . CursorPath ) . ToList ( ) ;
227- files . Add ( $ "{ Program . TempPath } / installer.inf") ;
214+ files . Add ( @ $ "{ Program . TempPath } \ installer.inf") ;
228215
229216 if ( createZip )
230217 {
@@ -291,9 +278,7 @@ private static string CreateInstallerInfString(string packageName, IEnumerable<C
291278 private static void CreateZipFile ( string zipPath , IEnumerable < string > files )
292279 {
293280 if ( File . Exists ( zipPath ) )
294- {
295281 File . Delete ( zipPath ) ;
296- }
297282 using var archive = ZipFile . Open ( zipPath , ZipArchiveMode . Create ) ;
298283 var folder = Path . GetFileNameWithoutExtension ( zipPath ) ;
299284 foreach ( var file in files )
@@ -331,9 +316,7 @@ public static void InstallCursor(string installerFilePath)
331316 catch ( System . ComponentModel . Win32Exception ex )
332317 {
333318 if ( ex . NativeErrorCode != 1223 )
334- {
335319 throw new Exception ( ex . Message + Environment . NewLine + ex . ErrorCode ) ;
336- }
337320 }
338321 }
339322}
0 commit comments