30
30
31
31
# Cache file for pyrekordbox data
32
32
_cache_file_version = 2
33
- _cache_file = Path ( __file__ ). parent / "rb.cache"
33
+ _cache_file_name = "rb.cache"
34
34
35
35
# Define empty pyrekordbox configuration
36
36
__config__ = {
@@ -48,6 +48,25 @@ class InvalidApplicationDirname(Exception):
48
48
pass
49
49
50
50
51
+ def get_appdata_dir () -> Path :
52
+ """Returns the path of the application data directory.
53
+
54
+ On Windows, the application data is stored in `/Users/user/AppData/Roaming`.
55
+ On macOS the application data is stored in `~/Libary/Application Support`.
56
+ """
57
+ if sys .platform == "win32" :
58
+ # Windows: located in /Users/user/AppData/Roaming/
59
+ app_data = Path (os .environ ["AppData" ])
60
+ elif sys .platform == "darwin" :
61
+ # MacOS: located in ~/Library/Application Support/
62
+ app_data = Path ("~" ).expanduser () / "Library" / "Application Support"
63
+ else :
64
+ # Linux: not supported
65
+ logger .warning (f"OS { sys .platform } not supported!" )
66
+ return Path ("~" ).expanduser () / ".local" / "share"
67
+ return app_data
68
+
69
+
51
70
def get_pioneer_install_dir (path : Union [str , Path ] = None ) -> Path : # pragma: no cover
52
71
"""Returns the path of the Pioneer program installation directory.
53
72
@@ -426,12 +445,16 @@ def run(self):
426
445
427
446
428
447
def write_db6_key_cache (key : str ) -> None : # pragma: no cover
429
- """Writes the decrypted Rekordbox6 database key to the cache file.
448
+ r """Writes the decrypted Rekordbox6 database key to the cache file.
430
449
431
450
This method can also be used to manually cache the database key, provided
432
451
the user has found the key somewhere else. The key can be, for example,
433
452
found in some other projects that hard-coded it.
434
453
454
+ The cache file is stored in the application data directory of pyrekordbox:
455
+ Windows: `C:\Users\<user>\AppData\Roaming\pyrekordbox`
456
+ macOS: `~/Library/Application Support/pyrekordbox`
457
+
435
458
Parameters
436
459
----------
437
460
key : str
@@ -453,7 +476,12 @@ def write_db6_key_cache(key: str) -> None: # pragma: no cover
453
476
lines .append (f"version: { _cache_file_version } " )
454
477
lines .append ("dp: " + key )
455
478
text = "\n " .join (lines )
456
- with open (_cache_file , "w" ) as fh :
479
+
480
+ cache_file = get_appdata_dir () / "pyrekordbox" / _cache_file_name
481
+ if not cache_file .parent .exists ():
482
+ cache_file .parent .mkdir ()
483
+
484
+ with open (cache_file , "w" ) as fh :
457
485
fh .write (text )
458
486
# Set the config key to make sure the key is present after calling method
459
487
if __config__ ["rekordbox6" ]:
@@ -465,10 +493,13 @@ def write_db6_key_cache(key: str) -> None: # pragma: no cover
465
493
def _update_sqlite_key (opts , conf ):
466
494
cache_version = 0
467
495
pw , dp = "" , ""
468
- if _cache_file .exists (): # pragma: no cover
469
- logger .debug ("Found cache file %s" , _cache_file )
496
+
497
+ cache_file = get_appdata_dir () / "pyrekordbox" / _cache_file_name
498
+
499
+ if cache_file .exists (): # pragma: no cover
500
+ logger .debug ("Found cache file %s" , cache_file )
470
501
# Read cache file
471
- with open (_cache_file , "r" ) as fh :
502
+ with open (cache_file , "r" ) as fh :
472
503
text = fh .read ()
473
504
lines = text .splitlines ()
474
505
if lines [0 ].startswith ("version:" ):
0 commit comments