This PR backports the following pull requests:
- #12493 [wallet] Reopen CDBEnv after encryption instead of shutting down
- #14350 Add WalletLocation class
- #14320 [bugfix] wallet: Fix duplicate fileid detection
- #14552 wallet: detecting duplicate wallet by comparing the db filename.
- #11911 Free BerkeleyEnvironment instances when not in use
- #15297 wallet: Releases dangling files on BerkeleyEnvironment::Close