Alex Brainman | ac17fd4 | 2011-11-18 10:07:36 +1100 | [diff] [blame] | 1 | // Copyright 2010 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package mime |
| 6 | |
| 7 | import ( |
Alex Brainman | 89454b1 | 2015-04-23 15:04:35 +1000 | [diff] [blame] | 8 | "internal/syscall/windows/registry" |
Alex Brainman | ac17fd4 | 2011-11-18 10:07:36 +1100 | [diff] [blame] | 9 | ) |
| 10 | |
Brad Fitzpatrick | b86f393 | 2015-03-29 21:21:15 +0200 | [diff] [blame] | 11 | func init() { |
| 12 | osInitMime = initMimeWindows |
| 13 | } |
| 14 | |
| 15 | func initMimeWindows() { |
Alex Brainman | 89454b1 | 2015-04-23 15:04:35 +1000 | [diff] [blame] | 16 | names, err := registry.CLASSES_ROOT.ReadSubKeyNames(-1) |
| 17 | if err != nil { |
Alex Brainman | ac17fd4 | 2011-11-18 10:07:36 +1100 | [diff] [blame] | 18 | return |
| 19 | } |
Alex Brainman | 89454b1 | 2015-04-23 15:04:35 +1000 | [diff] [blame] | 20 | for _, name := range names { |
| 21 | if len(name) < 2 || name[0] != '.' { // looking for extensions only |
Alex Brainman | ac17fd4 | 2011-11-18 10:07:36 +1100 | [diff] [blame] | 22 | continue |
| 23 | } |
Alex Brainman | 89454b1 | 2015-04-23 15:04:35 +1000 | [diff] [blame] | 24 | k, err := registry.OpenKey(registry.CLASSES_ROOT, name, registry.READ) |
| 25 | if err != nil { |
Alex Brainman | ac17fd4 | 2011-11-18 10:07:36 +1100 | [diff] [blame] | 26 | continue |
| 27 | } |
Alex Brainman | 89454b1 | 2015-04-23 15:04:35 +1000 | [diff] [blame] | 28 | v, _, err := k.GetStringValue("Content Type") |
| 29 | k.Close() |
| 30 | if err != nil { |
Alex Brainman | ac17fd4 | 2011-11-18 10:07:36 +1100 | [diff] [blame] | 31 | continue |
| 32 | } |
Alex Brainman | 89454b1 | 2015-04-23 15:04:35 +1000 | [diff] [blame] | 33 | setExtensionType(name, v) |
Alex Brainman | ac17fd4 | 2011-11-18 10:07:36 +1100 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
| 37 | func initMimeForTests() map[string]string { |
| 38 | return map[string]string{ |
Jeff R. Allen | af12dc5 | 2014-08-28 08:22:54 -0700 | [diff] [blame] | 39 | ".PnG": "image/png", |
Alex Brainman | ac17fd4 | 2011-11-18 10:07:36 +1100 | [diff] [blame] | 40 | } |
| 41 | } |