TheAshenWolf / WakaTimeForUE

As all the other versions of Wakatime plugins for Unreal Engine lead to blank repos, I decided to make a plugin that actually has some code in it. I am no longer working on this plugin, but the community is, so feel free to contribute!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add an option to save the API key to the global WakaTime config if it isn't already there (currently only loading)

simonSlamka opened this issue · comments

Scan the user home directory, looking for the .wakatime.cfg file. If it isn't there, create it. If it is there, check if it contains an API key. If it does, do nothing. If it doesn't, ask the user to input it and save it in there as api_key=<apiKey>.

I believe the correct approach, in this case, would be to

  1. Check if the file exists
  2. If it does not, create it and write in two lines - [settings] and under it api_key = (API key)
  3. if it does, read the file, looking for the line containing api_key
  4. if said line exists, rewrite it with the new setting
  5. if it does not exist, look for the line containing [settings]
  6. if this line does exist, insert the API key under it
  7. if it does not, do step 2 at the end top of the file
  8. save and close file

[settings] should always be at the top

But yeah, you're right. I forgot about the [settings] descriptor. And if that line exists, I would leave it intact since we don't want to ask for a key on each launch.
It's unlikely to happen that the line would exist without the key value set (api_key= ).

Well, that's true... however, we still should check for it when saving, as the API key has to go under the settings category, as seen here.

https://github.com/wakatime/wakatime#configuring

I am checking for it in my current fork. Give me a moment and I'll finish it. I know, I said that I forgot about the settings and I'll put them in there.

Added, tested

Nice, glad to be of assistance.