Created
April 17, 2020 03:09
-
-
Save BenJuan26/faac41c979f31bf371a141626f9c0fa4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ExpandFlags parses the RawFlags and sets the Flags values accordingly. | |
| func (status *Status) ExpandFlags() { | |
| status.Flags.Docked = status.RawFlags&FlagDocked != 0 | |
| status.Flags.Landed = status.RawFlags&FlagLanded != 0 | |
| status.Flags.LandingGearDown = status.RawFlags&FlagLandingGearDown != 0 | |
| // etc. | |
| } | |
| func GetStatus() (*Status, error) { | |
| // Build the file path from the user's home directory. | |
| currentUser, _ := user.Current() | |
| logPath := filepath.FromSlash(currentUser.HomeDir + "/Saved Games/Frontier Developments/Elite Dangerous" | |
| statusFilePath := filepath.FromSlash(logPath + "/Status.json") | |
| // Open the file. | |
| statusFile, err := os.Open(statusFilePath) | |
| if err != nil { | |
| return nil, err | |
| } | |
| defer statusFile.Close() | |
| // Read the contents of the file. | |
| statusBytes, err := ioutil.ReadAll(statusFile) | |
| if err != nil { | |
| return nil, err | |
| } | |
| // Parse the JSON and store the contents in a Status object. | |
| var status *Status | |
| err = json.Unmarshal(statusBytes, status) | |
| if err != nil { | |
| return nil, err | |
| } | |
| // Expand the RawFlags integer into the boolean values in Flags. | |
| status.ExpandFlags() | |
| return status, nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment