HASS.Agent icon indicating copy to clipboard operation
HASS.Agent copied to clipboard

Bug: Default config storage locations not ideal

Open Swamp-Ig opened this issue 2 years ago • 8 comments

The default storage location for the config files, both for the satelite service and the agent, isn't correct according to windows application specs.

Expected behavior The satelite service and agent should realy both be installed under %ProgramFiles(x86)%\LAB02 Research\. The agent is getting installed in %AppData%. This isn't ideal because it is potentially subject to folder redirection and/or roaming profiles in a domain environment. This also stops the installer from working correctly if run as a regular user.

The config data files for the satelite service really should live in %ProgramData%\LAB02 Research\HASS.Agent Satellite Service\, as %ProgramFiles% is not supposed to be writable.

The data files for the user agent should really be in %LocalAppData%rather than%AppData%because%AppData%` is supposed to roam with the user between computers on a domain, while local isn't. The local one is the right place since it's computer local config, otherwise things like the hostname for MQTT will stay the same on different machines, which isn't I suspect the goal.

Misc info (please complete the following information):

  • HASS.Agent version: 2022.12.0

Please check what's applicable (multiple answers possible):

  • [x] Installed via installer
  • [x] Installed manually
  • [x] Problem occurs in HASS.Agent
  • [x] Problem occurs in Satellite Service

Additional context I'm happy to code this up and PR it if you would like. I understand this might break existing installs, maybe set it up so it doesn't change anything for existing installs. I suspect the best approach would be to search first in %ProgramData% and %LocalAppData%, and then fall-back to the previous install location (eg: wherever the program runs from) if not found.

Part of the PR would be to update the default install location for the agent in the installer too.

Swamp-Ig avatar Aug 31 '22 07:08 Swamp-Ig

This is kinda related to: https://lab02research.youtrack.cloud/issue/hassagent-23

Swamp-Ig avatar Aug 31 '22 08:08 Swamp-Ig

It would also fix: https://lab02research.youtrack.cloud/issue/hassagent-79

Swamp-Ig avatar Aug 31 '22 08:08 Swamp-Ig

Hey @Swamp-Ig,

I agree that it's not ideal currently, and I don't have a problem with it moving to programdata. If you have the time to write a PR that'd be great of course! Shouldn't be too much work. Most code would probably be moving the current config to the new location before loading it - I try to keep everything as easy to use as possible. Maybe there should also be some cleanup code so users don't accidentally visit the old location for logs etc. Both functions could be added to this form; it gets launched elevated after an update, and it restarts HASS.Agent afterwards.

I'd suggest a %username% subfolder for hass.agent's config files. Logging would need to move as well, also to a %username% subfolder.

You can use this project for testing/your PR: https://github.com/LAB02-Research/HASS.Agent.Staging Some info: https://hassagent.readthedocs.io/en/latest/development/introduction/

LAB02-Admin avatar Aug 31 '22 08:08 LAB02-Admin

Coolies %LocalAppData% is per user anyhow, so it doesn't need to be subdivided out.

There would even be an argument for having the config in %programfiles% override config in %programdata% and %localappdata%, That way potentially the admin can set up machine-wide overrrides. This has all sorts of uses if you're coding up a bespoke parental or management monitoring and control application.

Ideally also the user agent should publish under something like HASSAGENT_<machine-name>_<user-name>, but that would be outside the scope of this PR.

Swamp-Ig avatar Aug 31 '22 08:08 Swamp-Ig

%LocalAppData% is per user anyhow, so it doesn't need to be subdivided out.

Yep, ok. Had in mind that the current folder structure would be moved to programdata, but keeping the user based stuff in their own localappdata makes more sense of course. I'll add a few buttons in the config panel to easily open all different folders.

There would even be an argument for having the config in %programfiles% override config in %programdata% and %localappdata%, That way potentially the admin can set up machine-wide overrrides.

That's a nice idea, agreed.

Ideally also the user agent should publish under something like HASSAGENT__, but that would be outside the scope of this PR.

Also a good idea.

LAB02-Admin avatar Aug 31 '22 08:08 LAB02-Admin

OK cool. I have a few things on at the moment but should be able to sort this out in the next few weeks.

Swamp-Ig avatar Aug 31 '22 09:08 Swamp-Ig

Ok working on this gradually.

I figure the service should move its own stuff around when it's started up, rather than during the update process. Does that make sense to you? Can move it to the PostUpdate form though if you like.

Swamp-Ig avatar Sep 04 '22 13:09 Swamp-Ig

Sorry for the late reply, but yea having the service handle its own stuff is fine

LAB02-Admin avatar Sep 08 '22 07:09 LAB02-Admin

Hi @Swamp-Ig,

Just checking up on this. There's been a new release with a bunch of code changes, but I don't think it should be in your way too much, you should be able to fetch the new code without problems.

Is there anything I can help with? If you don't have time for this, no worries, you can always just send me your progress so far and I'll pick it up from there.

LAB02-Admin avatar Nov 01 '22 09:11 LAB02-Admin

Oh sorry, have been busy with other things. I did look into it briefly but then got side-tracked. Might have some time in the next few weeks.

Swamp-Ig avatar Nov 01 '22 09:11 Swamp-Ig

Hey, just so you know, started doing a bit of work on this today as I'm off work with COVID. Haven't got very far though because I'm exhausted!

Swamp-Ig avatar Nov 16 '22 06:11 Swamp-Ig

Awesome @Swamp-Ig, but really take your time! I could hardly write two lines of code when I had it 😞 Hope you get well soon

LAB02-Admin avatar Nov 16 '22 08:11 LAB02-Admin