[ENHANCEMENT] `MMKV.exists(..)` API
Hey!
I was wondering if there's a way to find out if an MMKV instance with the given id exists or not?
Something like
auto id = "my-instance";
bool exists = MMKV::exists(id);
if (exists) {
// load it, start app
} else {
// show login page
}
This would maybe also open up other scenarios for e.g. crypto wallets, where we can check if an encrypted MMKV instance exists without knowing the encryption key.
No there isn't one yet. Will you be kindly enough to make a PR to add one?
Sure, can you give me some pointers on how I can find out if an instance exists? Try loading it? Looking for the file path? Some code pointers would be appreciated!
You can follow the logic in removeStorage(). Checking the existence of the file and meta file should be enough.
Created a draft PR here; https://github.com/Tencent/MMKV/pull/1347
Did not test yet, I'm still on the airport. Will test & finish it later.
Hey @lingol sorry this is a bit unrelated but I didn't want to create a separate issue for my question; when I create an instance with an encryption key and write some data to it, and then try to open it again later with a different encryption key (or no encryption key at all), it will erase all data of that instance.
Is that intended behaviour? I would've expected it to throw some kind of error if the encryption key does not match..
MMKV doesn't record the encryption key. So there's no way for MMKV to tell if the key is correct. Image that if MMKV does provide such functionality, doesn't that leave space for brute force encryption key cracking?
Okay valid. Got it.
Hey, is there any chance you can provide this feature this week? I'm considering a new release due to the encryption bug. I hope you can make it.
Hey - sorry I got stuck up with some other work related to my camera library. I think I won't be able to finish it this week, I might be able to dedicated the time for that next week or the week after that.
Of cause, take your time. We will release LTS version instead.
Hey, it's been some time. I've decided to officially add this feature. Thanks for the idea.
this is dope, thanks so much!