Store saves the current sequence value in the registry.
()
| 71 | |
| 72 | // Store saves the current sequence value in the registry. |
| 73 | func (s *Sequencer) Store() error { |
| 74 | if s.key == invalidKey { |
| 75 | // try to open the key again |
| 76 | var err error |
| 77 | access := uint32(registry.QUERY_VALUE | registry.SET_VALUE) |
| 78 | s.key, err = registry.OpenKey(registry.CURRENT_USER, "Volatile Environment", access) |
| 79 | if err != nil { |
| 80 | return errInvalidVolatileKey |
| 81 | } |
| 82 | } |
| 83 | nextSeq := s.Get() |
| 84 | prevSeq, _, err := s.key.GetIntegerValue(seqVName) |
| 85 | if err == nil && nextSeq < prevSeq { |
| 86 | return fmt.Errorf("current sequence number %d is lower than registry value %d", nextSeq, prevSeq) |
| 87 | } |
| 88 | return s.key.SetQWordValue(seqVName, nextSeq) |
| 89 | } |
| 90 | |
| 91 | // Increment increments the sequence number atomically. |
| 92 | func (s *Sequencer) Increment() { |