@@ -101,52 +101,52 @@ private static async Task<bool> ApplyIcon(DownloadIconParameters args) {
101
101
}
102
102
103
103
private static async Task < bool > TryGetIcon ( DownloadIconParameters parameters ) {
104
-
105
- // Validate Origin
106
- if ( string . IsNullOrWhiteSpace ( parameters . Origin ) ) {
107
- Console . WriteLine ( ConsoleTextStore . CommandEndFailure ( "Error: The origin of the icon is not specified." ) ) ;
108
- return false ;
109
- }
110
104
111
- // Assume Origin could be either a URL or a file path
112
- bool isUrl = Uri . TryCreate ( parameters . Origin , UriKind . Absolute , out Uri ? uriResult ) && ( uriResult . Scheme == Uri . UriSchemeHttp || uriResult . Scheme == Uri . UriSchemeHttps ) ;
113
-
114
- // Placeholder for the final icon's path
115
- string destinationPath = Path . Combine ( parameters . Root , parameters . IconFolder , "icon.png" ) ;
105
+ // Validate Origin
106
+ if ( string . IsNullOrWhiteSpace ( parameters . Origin ) ) {
107
+ Console . WriteLine ( ConsoleTextStore . CommandEndFailure ( "Error: The origin of the icon is not specified." ) ) ;
108
+ return false ;
109
+ }
116
110
117
- // create all folders if needed for the destination path
118
- Directory . CreateDirectory ( Path . GetDirectoryName ( destinationPath ) ! ) ;
111
+ // Assume Origin could be either a URL or a file path
112
+ bool isUrl = Uri . TryCreate ( parameters . Origin , UriKind . Absolute , out Uri ? uriResult ) && ( uriResult . Scheme == Uri . UriSchemeHttp || uriResult . Scheme == Uri . UriSchemeHttps ) ;
119
113
120
- if ( isUrl ) {
121
- // Download the file from URL using HttpClient
122
- using var client = new HttpClient ( ) ;
123
- Console . WriteLine ( $ "Downloading icon from URL: { parameters . Origin } ") ;
114
+ // Placeholder for the final icon's path
115
+ string destinationPath = Path . Combine ( parameters . Root , parameters . IconFolder , "icon.png" ) ;
124
116
125
- using HttpResponseMessage response = await client . GetAsync ( parameters . Origin ) ;
126
- if ( ! response . IsSuccessStatusCode ) {
127
- Console . WriteLine ( ConsoleTextStore . CommandEndFailure ( $ "Error: Failed to download the icon. HTTP Status: { response . StatusCode } ") ) ;
128
- return false ;
129
- }
117
+ // create all folders if needed for the destination path
118
+ Directory . CreateDirectory ( Path . GetDirectoryName ( destinationPath ) ! ) ;
130
119
131
- byte [ ] iconBytes = await response . Content . ReadAsByteArrayAsync ( ) ;
132
- await File . WriteAllBytesAsync ( destinationPath , iconBytes ) ;
120
+ if ( isUrl ) {
121
+ // Download the file from URL using HttpClient
122
+ using var client = new HttpClient ( ) ;
123
+ Console . WriteLine ( $ "Downloading icon from URL: { parameters . Origin } ") ;
133
124
134
- Console . WriteLine ( $ "Icon downloaded successfully to: { destinationPath } ") ;
125
+ using HttpResponseMessage response = await client . GetAsync ( parameters . Origin ) ;
126
+ if ( ! response . IsSuccessStatusCode ) {
127
+ Console . WriteLine ( ConsoleTextStore . CommandEndFailure ( $ "Error: Failed to download the icon. HTTP Status: { response . StatusCode } ") ) ;
128
+ return false ;
135
129
}
136
- else {
137
- // Treat as file system path and copy the icon
138
- Console . WriteLine ( $ "Copying icon from local path: { parameters . Origin } ") ;
139
130
140
- if ( ! File . Exists ( parameters . Origin ) ) {
141
- Console . WriteLine ( ConsoleTextStore . CommandEndFailure ( $ "Error: The specified origin file does not exist: { parameters . Origin } ") ) ;
142
- return false ;
143
- }
131
+ byte [ ] iconBytes = await response . Content . ReadAsByteArrayAsync ( ) ;
132
+ await File . WriteAllBytesAsync ( destinationPath , iconBytes ) ;
133
+
134
+ Console . WriteLine ( $ "Icon downloaded successfully to: { destinationPath } ") ;
135
+ }
136
+ else {
137
+ // Treat as file system path and copy the icon
138
+ Console . WriteLine ( $ "Copying icon from local path: { parameters . Origin } ") ;
144
139
145
- File . Copy ( parameters . Origin , destinationPath , true ) ;
146
- Console . WriteLine ( $ "Icon copied successfully to: { destinationPath } ") ;
140
+ if ( ! File . Exists ( parameters . Origin ) ) {
141
+ Console . WriteLine ( ConsoleTextStore . CommandEndFailure ( $ "Error: The specified origin file does not exist: { parameters . Origin } ") ) ;
142
+ return false ;
147
143
}
148
144
149
- // If all operations succeed
150
- return true ;
145
+ File . Copy ( parameters . Origin , destinationPath , true ) ;
146
+ Console . WriteLine ( $ "Icon copied successfully to: { destinationPath } ") ;
147
+ }
148
+
149
+ // If all operations succeed
150
+ return true ;
151
151
}
152
152
}
0 commit comments