@@ -177,85 +177,32 @@ public bool RegisterExtension(string fileExtension, string extensionId, string a |
177 | 177 | { |
178 | 178 | var classesRoot = Registry.ClassesRoot; |
179 | 179 |
|
180 | | - try |
181 | | - { |
182 | | - classesRoot.CreateSubKey(fileExtension); |
183 | | - } |
184 | | - catch (Exception) |
185 | | - { |
186 | | - |
187 | | - } |
188 | | - using (var fileExtensionKey = classesRoot.OpenSubKey(fileExtension, true)) |
| 180 | + using (var fileExtensionKey = classesRoot.CreateSubKey(fileExtension)) |
189 | 181 | { |
190 | 182 | fileExtensionKey?.SetValue(string.Empty, extensionId, RegistryValueKind.String); |
191 | 183 | } |
192 | 184 |
|
193 | | - try |
194 | | - { |
195 | | - classesRoot.CreateSubKey(extensionId); |
196 | | - } |
197 | | - catch (Exception) |
198 | | - { |
199 | | - |
200 | | - } |
201 | | - using (var extensionInfoKey = classesRoot.OpenSubKey(extensionId, true)) |
| 185 | + using (var extensionInfoKey = classesRoot.CreateSubKey(extensionId)) |
202 | 186 | { |
203 | 187 | extensionInfoKey?.SetValue(string.Empty, applicationName, RegistryValueKind.String); |
204 | 188 |
|
205 | | - try |
206 | | - { |
207 | | - extensionInfoKey?.CreateSubKey("DefaultIcon"); |
208 | | - } |
209 | | - catch (Exception) |
210 | | - { |
211 | | - |
212 | | - } |
213 | | - |
214 | | - using (var icon = extensionInfoKey?.OpenSubKey("DefaultIcon", true)) |
| 189 | + using (var icon = extensionInfoKey?.CreateSubKey("DefaultIcon")) |
215 | 190 | { |
216 | 191 | if (applicationPath.IndexOfAny(new[] { ' ', '\t' }) < 0) |
217 | 192 | { |
218 | | - icon?.SetValue(string.Empty, applicationPath + ",0", RegistryValueKind.String); |
219 | | - } |
220 | | - else |
221 | | - { |
222 | | - icon?.SetValue(string.Empty, "\"" + applicationPath + "\",0", RegistryValueKind.String); |
| 193 | + applicationPath = "\"" + applicationPath + "\""; |
223 | 194 | } |
224 | | - } |
225 | 195 |
|
226 | | - try |
227 | | - { |
228 | | - extensionInfoKey?.CreateSubKey("shell"); |
229 | | - } |
230 | | - catch (Exception) |
231 | | - { |
| 196 | + icon?.SetValue(string.Empty, "\"" + applicationPath + "\",0", RegistryValueKind.String); |
232 | 197 | } |
233 | | - using (var shellKey = extensionInfoKey?.OpenSubKey("shell", true)) |
234 | | - { |
235 | | - try |
236 | | - { |
237 | | - shellKey?.CreateSubKey("open"); |
238 | | - } |
239 | | - catch (Exception) |
240 | | - { |
241 | | - |
242 | | - } |
243 | 198 |
|
244 | | - using (var openKey = shellKey?.OpenSubKey("open", true)) |
| 199 | + using (var shellKey = extensionInfoKey?.CreateSubKey("shell")) |
| 200 | + { |
| 201 | + using (var openKey = shellKey?.CreateSubKey("open")) |
245 | 202 | { |
246 | | - |
247 | 203 | openKey?.SetValue(string.Empty, $"&Open with {applicationName}", RegistryValueKind.String); |
248 | 204 |
|
249 | | - try |
250 | | - { |
251 | | - openKey?.CreateSubKey("command"); |
252 | | - } |
253 | | - catch (Exception) |
254 | | - { |
255 | | - |
256 | | - } |
257 | | - |
258 | | - using (var commandKey = openKey?.OpenSubKey("command", true)) |
| 205 | + using (var commandKey = openKey?.CreateSubKey("command")) |
259 | 206 | { |
260 | 207 | commandKey?.SetValue(string.Empty, $"\"{applicationPath}\" \"%1\"", RegistryValueKind.String); |
261 | 208 | } |
|