Compare commits

...

188 Commits

Author SHA1 Message Date
Zhe Fang
48bdffb2fe Merge pull request #179 from jayfunc/l10n_dev
New Crowdin updates
2025-12-28 21:37:57 -05:00
Zhe Fang
d324a7552f New translations resources.resw (Chinese Traditional) 2025-12-28 21:37:17 -05:00
Zhe Fang
78c308c393 New translations resources.resw (Japanese) 2025-12-28 21:37:15 -05:00
Zhe Fang
a1bba00db6 chores: i18n 2025-12-28 21:31:37 -05:00
Zhe Fang
0787f5b111 fix 2025-12-28 21:10:02 -05:00
Zhe Fang
884026594b fix: ignore system, hidden files and unsupported format files 2025-12-28 21:03:56 -05:00
Zhe Fang
b0a777db8d chores: adjust layout and fix bugs 2025-12-28 20:01:41 -05:00
Zhe Fang
83f3a3bd6d chores: fix SMB and local file system, add auto-sync, improve lyruics search, album art search, local music gallery load speed (after 1st time) 2025-12-27 15:25:49 -05:00
Zhe Fang
bfb2ed29e5 fix: window title is synced with config name 2025-12-25 13:44:43 -05:00
Zhe Fang
131a0f0eb1 Merge pull request #172 from jayfunc/l10n_dev
New Crowdin updates
2025-12-24 19:24:20 -05:00
Zhe Fang
ac2a7b3f7b New translations resources.resw (Malay) 2025-12-24 19:22:52 -05:00
Zhe Fang
36eea7f8f2 New translations resources.resw (Hindi) 2025-12-24 19:22:52 -05:00
Zhe Fang
6b338deb55 New translations resources.resw (Thai) 2025-12-24 19:22:51 -05:00
Zhe Fang
af323ecd00 New translations resources.resw (Indonesian) 2025-12-24 19:22:50 -05:00
Zhe Fang
c79d01c75b New translations resources.resw (Vietnamese) 2025-12-24 19:22:49 -05:00
Zhe Fang
b51ec1e60f New translations resources.resw (Chinese Traditional) 2025-12-24 19:22:48 -05:00
Zhe Fang
7fe925bcba New translations resources.resw (Chinese Simplified) 2025-12-24 19:22:47 -05:00
Zhe Fang
0626472d66 New translations resources.resw (Russian) 2025-12-24 19:22:46 -05:00
Zhe Fang
33099bc186 New translations resources.resw (Portuguese) 2025-12-24 19:22:45 -05:00
Zhe Fang
e653efc227 New translations resources.resw (Korean) 2025-12-24 19:22:44 -05:00
Zhe Fang
074fef3faf New translations resources.resw (Japanese) 2025-12-24 19:22:43 -05:00
Zhe Fang
029cbbd343 New translations resources.resw (German) 2025-12-24 19:22:42 -05:00
Zhe Fang
802b2a4c1c New translations resources.resw (Arabic) 2025-12-24 19:22:41 -05:00
Zhe Fang
eccc4d519c New translations resources.resw (Spanish) 2025-12-24 19:22:39 -05:00
Zhe Fang
5f274ea28a New translations resources.resw (French) 2025-12-24 19:22:37 -05:00
Zhe Fang
aa1a1f5d58 chores: i18n 2025-12-24 19:22:16 -05:00
Zhe Fang
3a56d53487 New translations resources.resw (Malay) 2025-12-24 19:15:10 -05:00
Zhe Fang
bbc5eb772c New translations resources.resw (Hindi) 2025-12-24 19:15:09 -05:00
Zhe Fang
05b491052b New translations resources.resw (Thai) 2025-12-24 19:15:08 -05:00
Zhe Fang
8accbf0431 New translations resources.resw (Indonesian) 2025-12-24 19:15:07 -05:00
Zhe Fang
1174209c2a New translations resources.resw (Vietnamese) 2025-12-24 19:15:06 -05:00
Zhe Fang
23ed719046 New translations resources.resw (Chinese Traditional) 2025-12-24 19:15:05 -05:00
Zhe Fang
a34f00662e New translations resources.resw (Chinese Simplified) 2025-12-24 19:15:04 -05:00
Zhe Fang
f783314258 New translations resources.resw (Russian) 2025-12-24 19:15:03 -05:00
Zhe Fang
215a39c5d5 New translations resources.resw (Portuguese) 2025-12-24 19:15:02 -05:00
Zhe Fang
16bcef5f64 New translations resources.resw (Korean) 2025-12-24 19:15:01 -05:00
Zhe Fang
fbba9a3c36 New translations resources.resw (Japanese) 2025-12-24 19:15:00 -05:00
Zhe Fang
f205ab0364 New translations resources.resw (German) 2025-12-24 19:14:59 -05:00
Zhe Fang
10314f3c2f New translations resources.resw (Arabic) 2025-12-24 19:14:58 -05:00
Zhe Fang
b4710e87d3 New translations resources.resw (Spanish) 2025-12-24 19:14:57 -05:00
Zhe Fang
282a934cd2 New translations resources.resw (French) 2025-12-24 19:14:56 -05:00
Zhe Fang
b4c4e394ef Merge branch 'dev' of https://github.com/jayfunc/BetterLyrics into dev 2025-12-24 18:36:28 -05:00
Zhe Fang
17cfdf37bd chores: i18n 2025-12-24 18:36:26 -05:00
Zhe Fang
900a8e1e7c Update credit wording in CONTRIBUTING.md 2025-12-24 11:55:18 -05:00
Zhe Fang
ea9a9c2f5f Update translation contribution instructions in README
Added a link for contributors to find more information.
2025-12-24 11:52:00 -05:00
Zhe Fang
0c4d02b337 Revise translation assistance information
Updated translation assistance section with a link for contributions.
2025-12-24 11:51:38 -05:00
Zhe Fang
d137d82ecf Update translation assistance section in README
Added a section for translation assistance and removed the previous translation section.
2025-12-24 11:51:07 -05:00
Zhe Fang
02551e2053 Add translation contribution section to README
Added a section encouraging users to help translate the project and contribute.
2025-12-24 11:50:10 -05:00
Zhe Fang
026926e9b8 Update CONTRIBUTING.md 2025-12-24 11:39:08 -05:00
Zhe Fang
4c811db16a Update README.CN.md with translation and donation info
Added a section for translation contributions and donation support.
2025-12-24 11:36:29 -05:00
Zhe Fang
6f83fa11db Revise contributing guidelines for translations
Updated the contributing guidelines to include translation information in both English and Chinese. Added a status table for languages and contributors.
2025-12-24 11:34:55 -05:00
Zhe Fang
bc8e15c144 Update translation section in README.md
Added a section for translation contributions and removed the previous translation details.
2025-12-24 11:32:16 -05:00
Zhe Fang
85de1eb2cd Add Chinese translation guidelines to CONTRIBUTING.md 2025-12-24 11:29:00 -05:00
Zhe Fang
d2bf19ed3d Add translation contribution guidelines
Added instructions for translating BetterLyrics using Crowdin.
2025-12-24 11:27:23 -05:00
Zhe Fang
43c205c839 Update Japanese language support status in README 2025-12-24 11:07:35 -05:00
Zhe Fang
9664b1ab78 Update Japanese language entry in README.CN.md 2025-12-24 11:07:00 -05:00
Zhe Fang
08c5f6b515 Add contributor link for Japanese language support 2025-12-24 11:06:31 -05:00
Zhe Fang
260de40f81 Merge branch 'dev' of https://github.com/jayfunc/BetterLyrics into dev 2025-12-24 11:05:41 -05:00
Zhe Fang
c00d0eb005 fix: duration issue 2025-12-24 11:05:39 -05:00
Zhe Fang
32e761724c Merge pull request #170 from jayfunc/l10n_dev
New Crowdin updates
2025-12-24 11:05:05 -05:00
Zhe Fang
9fd08af582 New translations resources.resw (Japanese) 2025-12-24 11:03:57 -05:00
Zhe Fang
266dcfc930 New translations resources.resw (Chinese Simplified) 2025-12-24 10:43:52 -05:00
Zhe Fang
8764585f2c New translations resources.resw (Japanese) 2025-12-24 10:43:50 -05:00
Zhe Fang
91ab3a48c0 New translations resources.resw (Chinese Simplified) 2025-12-24 09:23:59 -05:00
Zhe Fang
80fa34d9e8 New translations resources.resw (Japanese) 2025-12-24 09:23:58 -05:00
Zhe Fang
b4ca4fd990 New translations resources.resw (Chinese Traditional) 2025-12-24 08:00:35 -05:00
Zhe Fang
86527f6b82 New translations resources.resw (Japanese) 2025-12-24 08:00:34 -05:00
Zhe Fang
d8066bc683 New translations resources.resw (Japanese) 2025-12-24 06:04:12 -05:00
Zhe Fang
b261a86791 New translations resources.resw (Japanese) 2025-12-24 04:35:20 -05:00
Zhe Fang
34f2a51b74 New translations resources.resw (Japanese) 2025-12-24 00:10:01 -05:00
Zhe Fang
b1e9c25e01 Merge branch 'dev' of https://github.com/jayfunc/BetterLyrics into dev 2025-12-23 20:43:31 -05:00
Zhe Fang
346de93c3f fix: AlbumArtThemeColors is not updated when PaletteGeneratorType is changed 2025-12-23 20:43:29 -05:00
Zhe Fang
6f48cbcd16 Add Contributor Covenant Code of Conduct
This document outlines the Contributor Covenant Code of Conduct, detailing our pledge, standards, enforcement responsibilities, and consequences for violations.
2025-12-23 18:02:06 -05:00
Zhe Fang
85b3121479 chores 2025-12-23 15:48:39 -05:00
Zhe Fang
94f00d1a31 chores 2025-12-23 14:10:35 -05:00
Zhe Fang
be9e4bba0f chores: update readme 2025-12-23 14:04:48 -05:00
Zhe Fang
2454927582 Merge pull request #169 from jayfunc/l10n_dev
New Crowdin updates
2025-12-23 13:44:27 -05:00
Zhe Fang
aca5f8e00d New translations resources.resw (Malay) 2025-12-23 13:43:43 -05:00
Zhe Fang
09709e8e62 New translations resources.resw (Hindi) 2025-12-23 13:43:42 -05:00
Zhe Fang
98fd8b43c4 New translations resources.resw (Thai) 2025-12-23 13:43:41 -05:00
Zhe Fang
3051180eb9 New translations resources.resw (Indonesian) 2025-12-23 13:43:38 -05:00
Zhe Fang
d48c81cfa1 New translations resources.resw (Vietnamese) 2025-12-23 13:43:37 -05:00
Zhe Fang
695147be9b New translations resources.resw (Portuguese) 2025-12-23 13:43:36 -05:00
Zhe Fang
e782944a44 New translations resources.resw (Arabic) 2025-12-23 13:43:35 -05:00
Zhe Fang
01462d42ce New translations resources.resw (Russian) 2025-12-23 13:43:33 -05:00
Zhe Fang
65b7dfcc44 New translations resources.resw (Japanese) 2025-12-23 13:43:31 -05:00
Zhe Fang
ec3146d4a7 New translations resources.resw (German) 2025-12-23 13:43:30 -05:00
Zhe Fang
9ec0bf0b1a New translations resources.resw (Spanish) 2025-12-23 13:43:29 -05:00
Zhe Fang
47e4b93613 New translations resources.resw (French) 2025-12-23 13:43:28 -05:00
Zhe Fang
192ad4a503 fix: i18n 2025-12-23 13:08:42 -05:00
Zhe Fang
091e33ae08 Merge branch 'dev' of https://github.com/jayfunc/BetterLyrics into dev 2025-12-23 13:04:44 -05:00
Zhe Fang
3b010ed674 add: more langs 2025-12-23 13:04:42 -05:00
Zhe Fang
a9f685d51b Merge pull request #168 from jayfunc/l10n_dev
New Crowdin updates
2025-12-23 13:04:04 -05:00
Zhe Fang
c6c31f8839 New translations resources.resw (Chinese Traditional) 2025-12-23 13:03:26 -05:00
Zhe Fang
78c53760cc New translations resources.resw (Chinese Simplified) 2025-12-23 13:03:25 -05:00
Zhe Fang
0bb6b5a204 New translations resources.resw (Chinese Traditional) 2025-12-23 12:34:51 -05:00
Zhe Fang
dff36a5e4d New translations resources.resw (Chinese Simplified) 2025-12-23 12:34:50 -05:00
Zhe Fang
0188e443db New translations resources.resw (Chinese Traditional) 2025-12-23 11:05:21 -05:00
Zhe Fang
5a9cdedc0c New translations resources.resw (Chinese Simplified) 2025-12-23 11:05:19 -05:00
Zhe Fang
31460fcc6d New translations resources.resw (Russian) 2025-12-23 11:05:18 -05:00
Zhe Fang
c12fc6f381 New translations resources.resw (Korean) 2025-12-23 11:05:16 -05:00
Zhe Fang
e5e0342994 New translations resources.resw (Japanese) 2025-12-23 11:05:15 -05:00
Zhe Fang
061958f20c New translations resources.resw (German) 2025-12-23 11:05:14 -05:00
Zhe Fang
95c73d0a34 New translations resources.resw (Spanish) 2025-12-23 11:05:13 -05:00
Zhe Fang
026a12ac87 New translations resources.resw (French) 2025-12-23 11:05:11 -05:00
Zhe Fang
da53f2166f Update contributors for Simplified Chinese section 2025-12-23 09:59:48 -05:00
Zhe Fang
717277e17c Update contributors for Simplified Chinese translation 2025-12-23 09:59:02 -05:00
Zhe Fang
1dc3ea57e9 chores: delete unused res items 2025-12-23 09:54:07 -05:00
Zhe Fang
4ec2ba8b59 chores: delete unused res item 2025-12-23 09:49:38 -05:00
Zhe Fang
91d9f253f0 Merge pull request #167 from jayfunc/l10n_dev
New Crowdin updates
2025-12-23 09:38:59 -05:00
Zhe Fang
90cf373e50 New translations resources.resw (Chinese Simplified) 2025-12-23 09:37:57 -05:00
Zhe Fang
cf2778da7a Add contributor table and translation invitation link 2025-12-23 09:27:10 -05:00
Zhe Fang
45ff7d7aa8 Update README with language and contributor information
Added a table listing supported languages and contributors.
2025-12-23 09:24:18 -05:00
Zhe Fang
eb37cb1b55 New translations resources.resw (Chinese Traditional) 2025-12-23 09:15:18 -05:00
Zhe Fang
45aa1d787d New translations resources.resw (Chinese Simplified) 2025-12-23 09:15:15 -05:00
Zhe Fang
0b28419ab5 New translations resources.resw (Russian) 2025-12-23 09:15:13 -05:00
Zhe Fang
258bf9220e New translations resources.resw (Korean) 2025-12-23 09:15:12 -05:00
Zhe Fang
9ece9f3edc New translations resources.resw (Japanese) 2025-12-23 09:15:11 -05:00
Zhe Fang
40c1f0a5ce New translations resources.resw (German) 2025-12-23 09:15:10 -05:00
Zhe Fang
5f75e6c63c New translations resources.resw (Spanish) 2025-12-23 09:15:09 -05:00
Zhe Fang
43387ce4c8 New translations resources.resw (French) 2025-12-23 09:15:08 -05:00
Zhe Fang
34eda9a262 fix: i18n 2025-12-23 08:51:38 -05:00
Zhe Fang
804673696f fix: i18n 2025-12-23 07:35:19 -05:00
Zhe Fang
b69e3bb24b chores: i18n 2025-12-23 07:12:36 -05:00
Zhe Fang
c028aa8e46 chores 2025-12-23 06:18:16 -05:00
Zhe Fang
fe3e257215 chores 2025-12-22 18:13:11 -05:00
Zhe Fang
eae2428d85 fix: lang 2025-12-22 17:19:09 -05:00
Zhe Fang
b078365136 fix: lang 2025-12-22 17:07:16 -05:00
Zhe Fang
1ede8dbef4 fix: song info fade 2025-12-22 16:45:41 -05:00
Zhe Fang
a66051b937 chores: i18n 2025-12-22 16:01:43 -05:00
Zhe Fang
1eca21c285 chores: i18n 2025-12-22 14:17:43 -05:00
Zhe Fang
2254a28e40 Merge branch 'dev' of https://github.com/jayfunc/BetterLyrics into dev 2025-12-22 11:47:30 -05:00
Zhe Fang
812eca369d chores: improve i18n method 2025-12-22 11:47:29 -05:00
Zhe Fang
132d3d8ac8 Merge pull request #164 from jayfunc/l10n_dev
New Crowdin updates
2025-12-22 11:46:56 -05:00
Zhe Fang
641a23621f New translations resources.resw (Chinese Simplified) 2025-12-22 11:46:00 -05:00
Zhe Fang
6802d10142 Merge pull request #163 from jayfunc/l10n_dev
New Crowdin updates
2025-12-22 06:47:45 -05:00
Zhe Fang
36f43e6d54 New translations resources.resw (Chinese Simplified) 2025-12-22 06:46:42 -05:00
Zhe Fang
e8298ec7bd New translations resources.resw (Chinese Simplified) 2025-12-22 06:33:43 -05:00
Zhe Fang
99a21cb935 New translations resources.resw (German) 2025-12-21 19:17:28 -05:00
Zhe Fang
b6da7bea5d New translations resources.resw (Chinese Traditional) 2025-12-21 19:17:27 -05:00
Zhe Fang
cf5bf75346 New translations resources.resw (Russian) 2025-12-21 19:17:26 -05:00
Zhe Fang
7497d7014d New translations resources.resw (Korean) 2025-12-21 19:17:24 -05:00
Zhe Fang
dd8c62ffa5 New translations resources.resw (Japanese) 2025-12-21 19:17:24 -05:00
Zhe Fang
15b147ba06 New translations resources.resw (Spanish) 2025-12-21 19:17:23 -05:00
Zhe Fang
85146ffc95 New translations resources.resw (French) 2025-12-21 19:17:22 -05:00
Zhe Fang
e9dce765e4 fix: i18n 2025-12-21 18:18:25 -05:00
Zhe Fang
3b2c4477b5 Merge pull request #162 from jayfunc/l10n_dev
New Crowdin updates
2025-12-21 18:07:48 -05:00
Zhe Fang
9d71c4aecf New translations resources.resw (German) 2025-12-21 18:02:53 -05:00
Zhe Fang
7184c148c4 New translations resources.resw (Chinese Traditional) 2025-12-21 18:02:52 -05:00
Zhe Fang
85f928ce3b New translations resources.resw (Chinese Simplified) 2025-12-21 18:02:51 -05:00
Zhe Fang
7c5032b0c2 New translations resources.resw (Russian) 2025-12-21 18:02:50 -05:00
Zhe Fang
2c3bd056b7 New translations resources.resw (Korean) 2025-12-21 18:02:49 -05:00
Zhe Fang
9f2843b7a0 New translations resources.resw (Japanese) 2025-12-21 18:02:48 -05:00
Zhe Fang
7fb6d5346e New translations resources.resw (Spanish) 2025-12-21 18:02:47 -05:00
Zhe Fang
27125d9051 New translations resources.resw (French) 2025-12-21 18:02:46 -05:00
Zhe Fang
5b2fb8b345 fix: english 2025-12-21 17:06:10 -05:00
Zhe Fang
d558811cb4 Merge pull request #161 from jayfunc/l10n_dev
New Crowdin updates
2025-12-21 16:58:03 -05:00
Zhe Fang
6e30aa7ebd New translations resources.resw (Chinese Traditional) 2025-12-21 16:56:21 -05:00
Zhe Fang
15fc337944 Merge pull request #160 from jayfunc/l10n_dev
New Crowdin updates
2025-12-21 16:46:11 -05:00
Zhe Fang
b7ef159b9e New translations resources.resw (German) 2025-12-21 16:44:37 -05:00
Zhe Fang
393b33ed83 New translations resources.resw (Chinese Traditional) 2025-12-21 16:44:36 -05:00
Zhe Fang
23dfda4413 New translations resources.resw (Chinese Simplified) 2025-12-21 16:44:35 -05:00
Zhe Fang
fde7340f4d New translations resources.resw (Russian) 2025-12-21 16:44:34 -05:00
Zhe Fang
22330d7fe9 New translations resources.resw (Korean) 2025-12-21 16:44:33 -05:00
Zhe Fang
c64e5776e8 New translations resources.resw (Japanese) 2025-12-21 16:44:32 -05:00
Zhe Fang
ffa2cd75a0 New translations resources.resw (Spanish) 2025-12-21 16:44:31 -05:00
Zhe Fang
873e75a7e9 New translations resources.resw (French) 2025-12-21 16:44:30 -05:00
Zhe Fang
ffa4101d5f chores: i18n 2025-12-21 16:26:35 -05:00
Zhe Fang
1c12b582c2 chores: add help us translate message 2025-12-21 16:22:32 -05:00
Zhe Fang
c50d31ced7 chores 2025-12-21 16:03:10 -05:00
Zhe Fang
f8108151b6 Merge pull request #159 from jayfunc/l10n_dev
New Crowdin updates
2025-12-21 16:02:22 -05:00
Zhe Fang
2932366767 New translations resources.resw (German) 2025-12-21 16:01:50 -05:00
Zhe Fang
cbf643ca70 Merge branch 'dev' of https://github.com/jayfunc/BetterLyrics into dev 2025-12-21 15:53:46 -05:00
Zhe Fang
a72d0f5c28 chores 2025-12-21 15:53:44 -05:00
Zhe Fang
3b4d98f9a3 Merge pull request #158 from jayfunc/l10n_dev
New Crowdin updates
2025-12-21 15:52:58 -05:00
Zhe Fang
d5828101d8 New translations resources.resw (Chinese Traditional) 2025-12-21 15:45:59 -05:00
Zhe Fang
56051537ea New translations resources.resw (Chinese Simplified) 2025-12-21 15:45:58 -05:00
Zhe Fang
6b465a09b1 New translations resources.resw (Russian) 2025-12-21 15:45:57 -05:00
Zhe Fang
450b86ebaf New translations resources.resw (Dutch) 2025-12-21 15:45:56 -05:00
Zhe Fang
c0078baa13 New translations resources.resw (Korean) 2025-12-21 15:45:55 -05:00
Zhe Fang
6b28212ec3 New translations resources.resw (Japanese) 2025-12-21 15:45:54 -05:00
Zhe Fang
9a3c2f5f70 New translations resources.resw (Spanish) 2025-12-21 15:45:54 -05:00
Zhe Fang
31be2bd8f7 New translations resources.resw (French) 2025-12-21 15:45:52 -05:00
Zhe Fang
47056e07a1 Merge branch 'dev' of https://github.com/jayfunc/BetterLyrics into dev 2025-12-21 15:03:32 -05:00
Zhe Fang
f30673b9d3 chores: add langs 2025-12-21 15:03:31 -05:00
Zhe Fang
d8624c49d0 Update Crowdin configuration file 2025-12-21 14:45:18 -05:00
Zhe Fang
72810e7440 Update Crowdin configuration file 2025-12-21 14:39:11 -05:00
Zhe Fang
e881d36743 chores: i18n 2025-12-21 14:34:34 -05:00
127 changed files with 21712 additions and 4648 deletions

View File

@@ -53,27 +53,27 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<AppxBundle>Always</AppxBundle>
<DefaultLanguage>en-US</DefaultLanguage>
<DefaultLanguage>en</DefaultLanguage>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
<AppxBundle>Always</AppxBundle>
<DefaultLanguage>en-US</DefaultLanguage>
<DefaultLanguage>en</DefaultLanguage>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<AppxBundle>Always</AppxBundle>
<DefaultLanguage>en-US</DefaultLanguage>
<DefaultLanguage>en</DefaultLanguage>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<AppxBundle>Always</AppxBundle>
<DefaultLanguage>en-US</DefaultLanguage>
<DefaultLanguage>en</DefaultLanguage>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
<AppxBundle>Always</AppxBundle>
<DefaultLanguage>en-US</DefaultLanguage>
<DefaultLanguage>en</DefaultLanguage>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
<AppxBundle>Always</AppxBundle>
<DefaultLanguage>en-US</DefaultLanguage>
<DefaultLanguage>en</DefaultLanguage>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">

View File

@@ -12,7 +12,7 @@
<Identity
Name="37412.BetterLyrics"
Publisher="CN=E1428B0E-DC1D-4EA4-ACB1-4556569D5BA9"
Version="1.1.203.0" />
Version="1.1.221.0" />
<mp:PhoneIdentity PhoneProductId="ca4a4830-fc19-40d9-b823-53e2bff3d816" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
@@ -28,11 +28,22 @@
</Dependencies>
<Resources>
<Resource Language="en-US"/>
<Resource Language="zh-CN"/>
<Resource Language="zh-TW"/>
<Resource Language="ja-JP"/>
<Resource Language="ko-KR"/>
<Resource Language="ar"/>
<Resource Language="de"/>
<Resource Language="en"/>
<Resource Language="es"/>
<Resource Language="fr"/>
<Resource Language="hi"/>
<Resource Language="id"/>
<Resource Language="ja"/>
<Resource Language="ko"/>
<Resource Language="ms"/>
<Resource Language="pt"/>
<Resource Language="ru"/>
<Resource Language="th"/>
<Resource Language="vi"/>
<Resource Language="zh-Hans"/>
<Resource Language="zh-Hant"/>
</Resources>
<Applications>

View File

@@ -75,6 +75,7 @@
<converter:LyricsLayoutOrientationToOrientationConverter x:Key="LyricsLayoutOrientationToOrientationConverter" />
<converter:LyricsLayoutOrientationNegationToOrientationConverter x:Key="LyricsLayoutOrientationNegationToOrientationConverter" />
<converter:FileSourceTypeToIconConverter x:Key="FileSourceTypeToIconConverter" />
<converter:PathToImageConverter x:Key="PathToImageConverter" />
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
@@ -96,7 +97,7 @@
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="CornerRadius" Value="4" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Padding" Value="14,6,14,9" />
<Setter Property="Padding" Value="16,9,16,9" />
<Setter Property="Background" Value="Transparent" />
</Style>
<Style x:Key="GhostButtonStyle" TargetType="Button">

View File

@@ -2,13 +2,14 @@
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Hooks;
using BetterLyrics.WinUI3.Models.Settings;
using BetterLyrics.WinUI3.Services.AlbumArtSearchService;
using BetterLyrics.WinUI3.Services.DiscordService;
using BetterLyrics.WinUI3.Services.FileSystemService;
using BetterLyrics.WinUI3.Services.LastFMService;
using BetterLyrics.WinUI3.Services.LibWatcherService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using BetterLyrics.WinUI3.Services.LyricsSearchService;
using BetterLyrics.WinUI3.Services.MediaSessionsService;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.SettingsService;
using BetterLyrics.WinUI3.Services.TranslationService;
using BetterLyrics.WinUI3.Services.TransliterationService;
@@ -19,8 +20,10 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml;
using Microsoft.Windows.ApplicationModel.Resources;
using Microsoft.Windows.Globalization;
using Serilog;
using System;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
@@ -71,6 +74,9 @@ namespace BetterLyrics.WinUI3
{
var settingsService = Ioc.Default.GetRequiredService<ISettingsService>();
var fileSystemService = Ioc.Default.GetRequiredService<IFileSystemService>();
fileSystemService.StartAllFolderTimers();
WindowHook.OpenOrShowWindow<SystemTrayWindow>();
if (settingsService.AppSettings.GeneralSettings.AutoStartLyricsWindow)
@@ -114,12 +120,12 @@ namespace BetterLyrics.WinUI3
.AddSingleton<IMediaSessionsService, MediaSessionsService>()
.AddSingleton<IAlbumArtSearchService, AlbumArtSearchService>()
.AddSingleton<ILyricsSearchService, LyricsSearchService>()
.AddSingleton<ILibWatcherService, LibWatcherService>()
.AddSingleton<ITranslationService, TranslationService>()
.AddSingleton<ITransliterationService, TransliterationService>()
.AddSingleton<ILastFMService, LastFMService>()
.AddSingleton<IResourceService, ResourceService>()
.AddSingleton<IDiscordService, DiscordService>()
.AddSingleton<ILocalizationService, LocalizationService>()
.AddSingleton<IFileSystemService, FileSystemService>()
// ViewModels
.AddSingleton<AppSettingsControlViewModel>()
.AddSingleton<PlaybackSettingsControlViewModel>()

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -10,13 +10,20 @@
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<AppxDefaultResourceQualifiers>Language=ar;de;en;es;fr;hi;id;ja;ko;ms;pt;ru;th;vi;zh-Hans;zh-Hant;</AppxDefaultResourceQualifiers>
</PropertyGroup>
<ItemGroup>
<Compile Remove="TemplateSelector\**" />
<Compile Remove="ViewModels\Lyrics\**" />
<Content Remove="TemplateSelector\**" />
<Content Remove="ViewModels\Lyrics\**" />
<EmbeddedResource Remove="TemplateSelector\**" />
<EmbeddedResource Remove="ViewModels\Lyrics\**" />
<None Remove="TemplateSelector\**" />
<None Remove="ViewModels\Lyrics\**" />
<Page Remove="TemplateSelector\**" />
<Page Remove="ViewModels\Lyrics\**" />
<PRIResource Remove="TemplateSelector\**" />
<PRIResource Remove="ViewModels\Lyrics\**" />
</ItemGroup>
<ItemGroup>
@@ -88,6 +95,7 @@
<PackageReference Include="Serilog.Extensions.Logging" Version="10.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
<PackageReference Include="SMBLibrary" Version="1.5.5.1" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
<PackageReference Include="System.Drawing.Common" Version="10.0.1" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="10.0.1" />
<PackageReference Include="TagLibSharp" Version="2.3.0" />
@@ -162,6 +170,9 @@
<Content Update="Assets\EmptyState.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="Assets\Folder.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Update="Assets\foobar2000.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
@@ -335,14 +346,6 @@
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<PRIResource Update="Strings\en-US\Resources.resw">
<Generator></Generator>
</PRIResource>
</ItemGroup>
<ItemGroup>
<Folder Include="TemplateSelector\" />
</ItemGroup>
<ItemGroup>
<Page Update="Controls\RemoteServerConfigControl.xaml">
<Generator>MSBuild:Compile</Generator>

View File

@@ -6,6 +6,8 @@
public const string AuthorGitHub = "https://github.com/jayfunc";
public const string Crowdin = "https://crowdin.com/project/betterlyrics/invite?h=413bb0df7afa420247a98fefdae5e12c2647410";
public const string BetterLyricsGitHub = $"{AuthorGitHub}/BetterLyrics";
public const string ShareHub = $"{BetterLyricsGitHub}/blob/dev/ShareHub/index.md";

View File

@@ -71,9 +71,9 @@
<StackPanel Spacing="6">
<TextBlock x:Uid="SetingsPageFeedback" />
<StackPanel Margin="-12,0,0,0" Orientation="Horizontal">
<HyperlinkButton x:Uid="SettingsPageQQGroup" NavigateUri="{x:Bind const:Link.QQGroup}" />
<HyperlinkButton x:Uid="SettingsPageDiscord" NavigateUri="{x:Bind const:Link.Discord}" />
<HyperlinkButton x:Uid="SettingsPageTelegram" NavigateUri="{x:Bind const:Link.Telegram}" />
<HyperlinkButton Content="QQ 反馈交流群" NavigateUri="{x:Bind const:Link.QQGroup}" />
<HyperlinkButton Content="Discord" NavigateUri="{x:Bind const:Link.Discord}" />
<HyperlinkButton Content="Telegram" NavigateUri="{x:Bind const:Link.Telegram}" />
</StackPanel>
</StackPanel>
</dev:SettingsCard>

View File

@@ -3,6 +3,7 @@
x:Class="BetterLyrics.WinUI3.Controls.AppSettingsControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:consts="using:BetterLyrics.WinUI3.Constants"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:dev="using:DevWinUI"
@@ -42,6 +43,14 @@
<Button x:Uid="SettingsPageRestart" Command="{x:Bind ViewModel.RestartAppCommand}" />
</dev:SettingsCard>
</dev:SettingsExpander.Items>
<dev:SettingsExpander.ItemsFooter>
<InfoBar IsClosable="False" IsOpen="True">
<HyperlinkButton
x:Uid="SettingsPageHelpUsTranslate"
Padding="0"
NavigateUri="{x:Bind consts:Link.Crowdin}" />
</InfoBar>
</dev:SettingsExpander.ItemsFooter>
</dev:SettingsExpander>
<!-- Startup -->

View File

@@ -6,7 +6,6 @@ using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System.Linq;
using static Vanara.PInvoke.User32.RAWINPUT;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

View File

@@ -81,14 +81,6 @@
Value="{x:Bind LyricsBackgroundSettings.CoverOverlayBlurAmount, Mode=TwoWay}" />
</dev:SettingsCard>
<!--<dev:SettingsCard x:Uid="SettingsPageBackgroundAcrylicEffectAmount" IsEnabled="{x:Bind LyricsBackgroundSettings.IsCoverOverlayEnabled, Mode=OneWay}">
<uc:ExtendedSlider
Default="0"
Maximum="10"
Minimum="0"
Value="{x:Bind LyricsBackgroundSettings.CoverAcrylicEffectAmount, Mode=TwoWay}" />
</dev:SettingsCard>-->
</dev:SettingsExpander.Items>
</dev:SettingsExpander>

View File

@@ -13,7 +13,6 @@ using BetterLyrics.WinUI3.Services.SettingsService;
using CommunityToolkit.Mvvm.DependencyInjection;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Lyricify.Lyrics.Providers.Web.Netease;
using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.UI.Xaml;
using Microsoft.UI;
@@ -21,13 +20,11 @@ using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Storage.Streams;
using Windows.UI;
using static Vanara.PInvoke.Ole32;
namespace BetterLyrics.WinUI3.Controls
{

View File

@@ -25,7 +25,7 @@
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<ScrollViewer>
<ScrollViewer Padding="8,0">
<StackPanel Spacing="{StaticResource SettingsCardSpacing}">
<TextBlock x:Uid="LyricsSearchControlSongInfoMapping" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />
@@ -153,12 +153,11 @@
<CheckBox x:Uid="LyricsSearchControlMarkAsPureMusic" IsChecked="{x:Bind ViewModel.MappedSongSearchQuery.IsMarkedAsPureMusic, Mode=TwoWay}" />
</dev:SettingsCard>
<dev:SettingsCard x:Uid="LyricsSearchControlTargetSearchProvider">
<Button
x:Uid="LyricsSearchControlSearch"
Command="{x:Bind ViewModel.SearchCommand}"
Style="{StaticResource AccentButtonStyle}" />
</dev:SettingsCard>
<Button
x:Uid="LyricsSearchControlSearch"
HorizontalAlignment="Stretch"
Command="{x:Bind ViewModel.SearchCommand}"
Style="{StaticResource AccentButtonStyle}" />
<dev:SettingsCard x:Uid="LyricsSearchControlIgnoreCache">
<ToggleSwitch IsOn="{x:Bind ViewModel.AppSettings.GeneralSettings.IgnoreCacheWhenSearching, Mode=TwoWay}" />
@@ -183,10 +182,7 @@
<local:PropertyRow x:Uid="SettingsPageSongTitle" Value="{x:Bind Title, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow x:Uid="SettingsPageArtist" Value="{x:Bind DisplayArtists, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow x:Uid="SettingsPageAlbum" Value="{x:Bind Album, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow
x:Uid="LyricsSearchControlDurauion"
Unit="s"
Value="{x:Bind Duration, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow x:Uid="LyricsSearchControlDurauion" Value="{x:Bind Duration, Converter={StaticResource SecondsToFormattedTimeConverter}, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow
x:Uid="LyricsPageMatchPercentage"
Unit="%"
@@ -244,8 +240,6 @@
<ProgressBar
VerticalAlignment="Top"
IsIndeterminate="True"
ShowError="False"
ShowPaused="False"
Visibility="{x:Bind ViewModel.IsSearching, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}" />
</Grid>
<Grid Grid.Column="2">
@@ -346,8 +340,8 @@
</Grid>
<Grid Grid.Row="1" ColumnSpacing="6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

View File

@@ -187,29 +187,51 @@
<controls:Segmented
x:Name="ConfigSegmented"
HorizontalAlignment="Stretch"
SelectionChanged="ConfigSegmented_SelectionChanged"
Style="{StaticResource PivotSegmentedStyle}">
<controls:SegmentedItem x:Name="WindowSegmentedItem" Tag="Window">
<TextBlock x:Uid="AppSettingsControlGeneral" />
<TextBlock
x:Uid="AppSettingsControlGeneral"
MaxWidth="120"
TextWrapping="Wrap" />
</controls:SegmentedItem>
<controls:SegmentedItem x:Name="LayoutSegmentedItem" Tag="Layout">
<TextBlock x:Uid="SettingsPageLayout" />
<TextBlock
x:Uid="SettingsPageLayout"
MaxWidth="120"
TextWrapping="Wrap" />
</controls:SegmentedItem>
<controls:SegmentedItem x:Name="AlbumArtStyleSegmentedItem" Tag="AlbumArtStyle">
<TextBlock x:Uid="SettingsPageAlbumStyle" />
<TextBlock
x:Uid="SettingsPageAlbumStyle"
MaxWidth="120"
TextWrapping="Wrap" />
</controls:SegmentedItem>
<controls:SegmentedItem Tag="AlbumArtEffect">
<TextBlock x:Uid="SettingsPageAlbumEffect" />
<TextBlock
x:Uid="SettingsPageAlbumEffect"
MaxWidth="120"
TextWrapping="Wrap" />
</controls:SegmentedItem>
<controls:SegmentedItem Tag="LyricsStyle">
<TextBlock x:Uid="SettingsPageLyricsStyle" />
<TextBlock
x:Uid="SettingsPageLyricsStyle"
MaxWidth="120"
TextWrapping="Wrap" />
</controls:SegmentedItem>
<controls:SegmentedItem Tag="LyricsEffect">
<TextBlock x:Uid="SettingsPageLyricsEffect" />
<TextBlock
x:Uid="SettingsPageLyricsEffect"
MaxWidth="120"
TextWrapping="Wrap" />
</controls:SegmentedItem>
<controls:SegmentedItem Tag="LyricsBackground">
<TextBlock x:Uid="SettingsPageBackgroundOverlay" />
<TextBlock
x:Uid="SettingsPageBackgroundOverlay"
MaxWidth="120"
TextWrapping="Wrap" />
</controls:SegmentedItem>
</controls:Segmented>

View File

@@ -10,7 +10,6 @@ using CommunityToolkit.WinUI.Controls;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

View File

@@ -1,5 +1,4 @@
using BetterLyrics.WinUI3.Hooks;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Services.SettingsService;
using BetterLyrics.WinUI3.ViewModels;
using BetterLyrics.WinUI3.Views;
@@ -7,7 +6,6 @@ using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using System.Linq;
using System.Threading.Tasks;
// To learn more about WinUI, the WinUI project structure,

View File

@@ -50,34 +50,76 @@
SelectionMode="None">
<ListView.ItemTemplate>
<DataTemplate x:DataType="models:MediaFolder">
<dev:SettingsExpander Description="{x:Bind ConnectionSummary, Mode=OneWay}" HeaderIcon="{Binding SourceType, Converter={StaticResource FileSourceTypeToIconConverter}}">
<dev:SettingsExpander IsExpanded="True">
<dev:SettingsExpander.HeaderIcon>
<FontIcon FontFamily="{StaticResource IconFontFamily}" Glyph="{x:Bind SourceType, Converter={StaticResource FileSourceTypeToIconConverter}, Mode=OneWay}" />
</dev:SettingsExpander.HeaderIcon>
<dev:SettingsExpander.Header>
<HyperlinkButton
Padding="0"
Click="LocalFolderHyperlinkButton_Click"
Content="{x:Bind Path, Mode=OneWay}"
Tag="{x:Bind Path, Mode=OneWay}"
ToolTipService.ToolTip="{x:Bind ConnectionSummary}" />
<TextBlock IsTextSelectionEnabled="True" Text="{x:Bind Name, Mode=OneWay}" />
</dev:SettingsExpander.Header>
<dev:SettingsExpander.Description>
<TextBlock IsTextSelectionEnabled="True" Text="{x:Bind ConnectionSummary, Mode=OneWay}" />
</dev:SettingsExpander.Description>
<ToggleSwitch IsOn="{x:Bind IsEnabled, Mode=TwoWay}" />
<dev:SettingsExpander.Items>
<dev:SettingsCard>
<dev:SettingsCard.Header>
<HyperlinkButton
x:Uid="SettingsPageRemovePath"
Padding="0"
Click="SettingsPageRemovePathButton_Click"
Tag="{Binding}" />
</dev:SettingsCard.Header>
<dev:SettingsCard x:Uid="MediaSettingsControlNameSetting">
<TextBox VerticalAlignment="Center" Text="{x:Bind Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</dev:SettingsCard>
<dev:SettingsCard x:Uid="SettingsPageMusicLibRealTimeWatch" IsEnabled="{Binding IsLocal, Mode=OneWay}">
<ToggleSwitch IsOn="{Binding IsRealTimeWatchEnabled, Mode=TwoWay}" />
<dev:SettingsCard x:Uid="MediaSettingsControlLastSyncTime" Description="{x:Bind LastSyncTime.ToString(), Mode=OneWay, TargetNullValue=N/A}">
<Button
x:Uid="MediaSettingsControlSyncNow"
Click="SyncNowButton_Click"
IsEnabled="{x:Bind IsEnabled, Mode=OneWay}" />
</dev:SettingsCard>
<dev:SettingsCard x:Uid="MusicSettingsControlAutoSyncInterval">
<ComboBox IsEnabled="{x:Bind IsEnabled, Mode=OneWay}" SelectedIndex="{x:Bind ScanInterval, Mode=TwoWay, Converter={StaticResource EnumToIntConverter}}">
<ComboBoxItem x:Uid="MusicSettingsControlAutoSyncIntervalDisabled" />
<ComboBoxItem x:Uid="MusicSettingsControlAutoSyncIntervalEveryFifteenMin" />
<ComboBoxItem x:Uid="MusicSettingsControlAutoSyncIntervalEveryHour" />
<ComboBoxItem x:Uid="MusicSettingsControlAutoSyncIntervalEverySixHrs" />
<ComboBoxItem x:Uid="MusicSettingsControlAutoSyncIntervalEveryDay" />
</ComboBox>
</dev:SettingsCard>
<dev:SettingsCard>
<Button x:Uid="SettingsPageRemovePath" Click="SettingsPageRemovePathButton_Click" />
</dev:SettingsCard>
</dev:SettingsExpander.Items>
<dev:SettingsExpander.ItemsFooter>
<StackPanel>
<!-- Index info -->
<InfoBar
IsClosable="False"
IsOpen="{x:Bind IsIndexing, Mode=OneWay}"
Message="{x:Bind IndexingStatusText, Mode=OneWay}" />
<ProgressBar Visibility="{x:Bind IsIndexing, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}" Value="{x:Bind IndexingProgress, Mode=OneWay}">
<interactivity:Interaction.Behaviors>
<interactivity:DataTriggerBehavior
Binding="{x:Bind IndexingProgress, Mode=OneWay}"
ComparisonCondition="Equal"
Value="0">
<interactivity:ChangePropertyAction PropertyName="IsIndeterminate" Value="True" />
</interactivity:DataTriggerBehavior>
<interactivity:DataTriggerBehavior
Binding="{x:Bind IndexingProgress, Mode=OneWay}"
ComparisonCondition="NotEqual"
Value="0">
<interactivity:ChangePropertyAction PropertyName="IsIndeterminate" Value="False" />
</interactivity:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ProgressBar>
<!-- Clean up info -->
<InfoBar
IsClosable="False"
IsOpen="{x:Bind IsCleaningUp, Mode=OneWay}"
Message="{x:Bind CleaningUpStatusText, Mode=OneWay}" />
<ProgressBar IsIndeterminate="True" Visibility="{x:Bind IsCleaningUp, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}" />
</StackPanel>
</dev:SettingsExpander.ItemsFooter>
</dev:SettingsExpander>
</DataTemplate>
</ListView.ItemTemplate>
@@ -89,14 +131,17 @@
<MenuFlyout>
<MenuFlyoutItem
x:Uid="SettingsPageLocalFolder"
Command="{x:Bind ViewModel.SelectAndAddFolderCommand}"
CommandParameter="{Binding ElementName=RootGrid}"
Icon="Folder" />
Command="{x:Bind ViewModel.AddMediaSourceCommand}"
CommandParameter="Local">
<MenuFlyoutItem.Icon>
<FontIcon FontFamily="{StaticResource IconFontFamily}" Glyph="&#xE8B7;" />
</MenuFlyoutItem.Icon>
</MenuFlyoutItem>
<MenuFlyoutSeparator />
<MenuFlyoutItem
Command="{x:Bind ViewModel.AddRemoteSourceCommand}"
Command="{x:Bind ViewModel.AddMediaSourceCommand}"
CommandParameter="SMB"
Text="SMB">
<MenuFlyoutItem.Icon>
@@ -105,7 +150,7 @@
</MenuFlyoutItem>
<MenuFlyoutItem
Command="{x:Bind ViewModel.AddRemoteSourceCommand}"
Command="{x:Bind ViewModel.AddMediaSourceCommand}"
CommandParameter="FTP"
Text="FTP">
<MenuFlyoutItem.Icon>
@@ -114,7 +159,7 @@
</MenuFlyoutItem>
<MenuFlyoutItem
Command="{x:Bind ViewModel.AddRemoteSourceCommand}"
Command="{x:Bind ViewModel.AddMediaSourceCommand}"
CommandParameter="WebDAV"
Text="WebDAV">
<MenuFlyoutItem.Icon>

View File

@@ -4,6 +4,7 @@ using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Threading.Tasks;
using Windows.System;
// To learn more about WinUI, the WinUI project structure,
@@ -22,18 +23,14 @@ namespace BetterLyrics.WinUI3.Controls
private void SettingsPageRemovePathButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
ViewModel.RemoveFolderAsync((MediaFolder)(sender as HyperlinkButton)!.Tag);
var folder = (MediaFolder)((FrameworkElement)sender).DataContext;
ViewModel.RemoveFolder(folder);
}
private async void LocalFolderHyperlinkButton_Click(object sender, RoutedEventArgs e)
private void SyncNowButton_Click(object sender, RoutedEventArgs e)
{
if (sender is HyperlinkButton button && button.Tag is string uriStr)
{
if (Uri.TryCreate(uriStr, UriKind.Absolute, out var uri))
{
await Launcher.LaunchUriAsync(uri);
}
}
var folder = (MediaFolder)((FrameworkElement)sender).DataContext;
ViewModel.SyncFolder(folder);
}
}
}

View File

@@ -44,10 +44,10 @@
</interactivity:Interaction.Behaviors>
<InfoBar
x:Uid="SettingsPageMusicGalleryOpened"
Grid.Row="0"
IsClosable="False"
IsOpen="{x:Bind ViewModel.AppSettings.MusicGallerySettings.LyricsWindowStatus.IsOpened, Mode=OneWay}"
Message="音乐库窗口已打开,将忽略对其他播放源的监听"
Severity="Informational" />
<!-- 播放源列表 -->
@@ -328,10 +328,7 @@
<local:PropertyRow x:Uid="SettingsPageSongTitle" Value="{x:Bind ViewModel.MediaSessionsService.CurrentSongInfo.Title, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow x:Uid="SettingsPageArtist" Value="{x:Bind ViewModel.MediaSessionsService.CurrentSongInfo.DisplayArtists, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow x:Uid="SettingsPageAlbum" Value="{x:Bind ViewModel.MediaSessionsService.CurrentSongInfo.Album, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow
x:Uid="LyricsSearchControlDurauion"
Unit="s"
Value="{x:Bind ViewModel.MediaSessionsService.CurrentSongInfo.Duration, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow x:Uid="LyricsSearchControlDurauion" Value="{x:Bind ViewModel.MediaSessionsService.CurrentSongInfo.DurationMs, TargetNullValue=N/A, Converter={StaticResource MillisecondsToFormattedTimeConverter}, Mode=OneWay}" />
</StackPanel>
</Expander>
@@ -344,10 +341,7 @@
<local:PropertyRow x:Uid="SettingsPageSongTitle" Value="{x:Bind ViewModel.MediaSessionsService.CurrentLyricsSearchResult.Title, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow x:Uid="SettingsPageArtist" Value="{x:Bind ViewModel.MediaSessionsService.CurrentLyricsSearchResult.DisplayArtists, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow x:Uid="SettingsPageAlbum" Value="{x:Bind ViewModel.MediaSessionsService.CurrentLyricsSearchResult.Album, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow
x:Uid="LyricsSearchControlDurauion"
Unit="s"
Value="{x:Bind ViewModel.MediaSessionsService.CurrentLyricsSearchResult.Duration, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow x:Uid="LyricsSearchControlDurauion" Value="{x:Bind ViewModel.MediaSessionsService.CurrentLyricsSearchResult.Duration, Converter={StaticResource SecondsToFormattedTimeConverter}, TargetNullValue=N/A, Mode=OneWay}" />
<local:PropertyRow x:Uid="LyricsPageLanguageCode" Value="{x:Bind ViewModel.MediaSessionsService.CurrentLyricsData.LanguageCode, TargetNullValue=N/A, Mode=OneWay, Converter={StaticResource LanguageCodeToDisplayedNameConverter}}" />
<local:PropertyRow
x:Uid="LyricsPageLyricsProviderPrefix"
@@ -467,9 +461,9 @@
</dev:SettingsCard>
<!-- Last.fm -->
<TextBlock x:Uid="SettingsPageLastFM" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="Last.fm" />
<dev:SettingsExpander
x:Uid="SettingsPageLastFMManager"
Header="Last.fm"
HeaderIcon="{ui:BitmapIcon Source=ms-appx:///Assets/LastFM.png}"
IsExpanded="{x:Bind ViewModel.IsLastFMAuthenticated, Mode=OneWay}">
<StackPanel Orientation="Horizontal" Spacing="6">

View File

@@ -9,58 +9,85 @@
mc:Ignorable="d">
<Grid>
<StackPanel Width="400" Spacing="16">
<ProgressBar
x:Name="ProgressBar"
IsIndeterminate="True"
Visibility="Collapsed" />
<InfoBar
x:Name="ErrorInfoBar"
IsClosable="True"
IsOpen="False"
Severity="Error" />
<ScrollViewer>
<StackPanel Width="400" Spacing="16">
<ProgressBar
x:Name="ProgressBar"
IsIndeterminate="True"
Visibility="Collapsed" />
<InfoBar
x:Name="ErrorInfoBar"
IsClosable="True"
IsOpen="False"
Severity="Error" />
<Grid ColumnDefinitions="*, Auto" ColumnSpacing="12">
<TextBox
x:Name="HostBox"
x:Uid="RemoteServerConfigControlServerAddress"
Grid.Column="0"
Header="Server Address"
InputScope="Url"
PlaceholderText="192.168.1.x"
x:Name="NameBox"
x:Uid="RemoteServerConfigControlName"
TextWrapping="Wrap" />
<NumberBox
x:Name="PortBox"
x:Uid="RemoteServerConfigControlPort"
Grid.Column="1"
MinWidth="100"
Header="Port"
LargeChange="10"
SmallChange="1"
SpinButtonPlacementMode="Inline"
ToolTipService.ToolTip="80"
Value="80" />
</Grid>
<StackPanel x:Name="RemoteFieldsPanel" Spacing="16">
<Grid ColumnDefinitions="*, Auto" ColumnSpacing="12">
<TextBox
x:Name="HostBox"
x:Uid="RemoteServerConfigControlServerAddress"
Grid.Column="0"
InputScope="Url"
PlaceholderText="192.168.1.x"
TextWrapping="Wrap" />
<TextBox
x:Name="PathBox"
x:Uid="RemoteServerConfigControlPath"
TextWrapping="Wrap" />
<NumberBox
x:Name="PortBox"
x:Uid="RemoteServerConfigControlPort"
Grid.Column="1"
MinWidth="100"
LargeChange="10"
SmallChange="1"
SpinButtonPlacementMode="Inline"
ToolTipService.ToolTip="80"
Value="80" />
</Grid>
</StackPanel>
<Grid ColumnDefinitions="*, *" ColumnSpacing="12">
<TextBox
x:Name="UserBox"
x:Uid="RemoteServerConfigControlUsername"
Grid.Column="0"
TextWrapping="Wrap" />
<Grid ColumnDefinitions="*, Auto" ColumnSpacing="8">
<TextBox
x:Name="PathBox"
x:Uid="RemoteServerConfigControlPath"
Grid.Column="0"
TextChanged="PathBox_TextChanged"
TextWrapping="Wrap" />
<PasswordBox
x:Name="PwdBox"
x:Uid="RemoteServerConfigControlPassword"
Grid.Column="1"
PasswordRevealMode="Peek" />
</Grid>
</StackPanel>
<Button
x:Name="BrowseButton"
x:Uid="RemoteServerConfigControlBrowse"
Grid.Column="1"
VerticalAlignment="Bottom"
Click="BrowseButton_Click"
Visibility="Collapsed" />
</Grid>
<InfoBar
x:Name="PathWarningBar"
IsClosable="False"
IsOpen="False"
Severity="Warning" />
<StackPanel x:Name="AuthFieldsPanel" Spacing="16">
<Grid ColumnDefinitions="*, *" ColumnSpacing="12">
<TextBox
x:Name="UserBox"
x:Uid="RemoteServerConfigControlUsername"
Grid.Column="0"
TextWrapping="Wrap" />
<PasswordBox
x:Name="PwdBox"
x:Uid="RemoteServerConfigControlPassword"
Grid.Column="1"
PasswordRevealMode="Peek" />
</Grid>
</StackPanel>
</StackPanel>
</ScrollViewer>
</Grid>
</UserControl>

View File

@@ -1,22 +1,19 @@
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using BetterLyrics.WinUI3.Views;
using CommunityToolkit.Mvvm.DependencyInjection;
using DevWinUI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using Windows.Storage;
namespace BetterLyrics.WinUI3.Controls
{
public sealed partial class RemoteServerConfigControl : UserControl
{
private readonly string _protocolType;
private readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
public RemoteServerConfigControl(string protocolType)
{
@@ -24,81 +21,123 @@ namespace BetterLyrics.WinUI3.Controls
_protocolType = protocolType;
SetupDefaults();
CheckPathForWarning();
}
private void SetupDefaults()
{
if (_protocolType.Equals("Local", StringComparison.OrdinalIgnoreCase))
{
RemoteFieldsPanel.Visibility = Visibility.Collapsed;
AuthFieldsPanel.Visibility = Visibility.Collapsed;
BrowseButton.Visibility = Visibility.Visible;
PathBox.PlaceholderText = @"D:\Music";
}
else
{
BrowseButton.Visibility = Visibility.Collapsed;
RemoteFieldsPanel.Visibility = Visibility.Visible;
AuthFieldsPanel.Visibility = Visibility.Visible;
switch (_protocolType.ToUpper())
{
case "SMB":
PortBox.Value = 445;
PathBox.PlaceholderText = "SharedMusic";
break;
case "FTP":
PortBox.Value = 21;
PathBox.PlaceholderText = "/pub/music";
break;
case "WEBDAV":
PortBox.Value = 80;
PathBox.PlaceholderText = "/dav/music";
break;
}
}
}
private string GetScheme()
{
string scheme = string.Empty;
switch (_protocolType.ToUpper())
{
case "SMB":
PortBox.Value = 445; // SMB Ĭ<>϶˿<CFB6>
PathBox.PlaceholderText = "SharedMusic";
scheme = "smb";
break;
case "FTP":
PortBox.Value = 21; // FTP Ĭ<>϶˿<CFB6>
PathBox.PlaceholderText = "/pub/music";
scheme = "ftp";
break;
case "WEBDAV":
PortBox.Value = 80; // WebDAV Ĭ<>϶˿<CFB6>
PathBox.PlaceholderText = "/dav/music";
scheme = "https";
break;
}
return scheme;
}
public MediaFolder GetConfig()
{
if (string.IsNullOrWhiteSpace(HostBox.Text))
throw new ArgumentException(_resourceService.GetLocalizedString("RemoteServerConfigControlServerAddressRequired"));
string finalName = HostBox.Text.Trim();
string name = $"{_protocolType} - {HostBox.Text}";
if (_protocolType.Equals("Local", StringComparison.OrdinalIgnoreCase))
{
if (string.IsNullOrWhiteSpace(PathBox.Text))
throw new ArgumentException(_localizationService.GetLocalizedString("RemoteServerConfigControlPathRequired"));
if (!string.IsNullOrWhiteSpace(NameBox.Text))
finalName = NameBox.Text.Trim();
else
finalName = PathBox.Text.TrimEnd(System.IO.Path.DirectorySeparatorChar);
return new MediaFolder
{
Name = finalName,
SourceType = FileSourceType.Local,
UriScheme = "file",
UriPath = PathBox.Text.Trim(),
};
}
if (string.IsNullOrWhiteSpace(HostBox.Text))
throw new ArgumentException(_localizationService.GetLocalizedString("RemoteServerConfigControlServerAddressRequired"));
if (!string.IsNullOrWhiteSpace(NameBox.Text))
{
finalName = NameBox.Text.Trim();
}
else
{
finalName = $"{_protocolType} - {HostBox.Text}";
}
Enum.TryParse(_protocolType, true, out FileSourceType sourceType);
string scheme = GetScheme();
var folder = new MediaFolder
{
Name = name,
Path = HostBox.Text, // <20><><EFBFBD><EFBFBD> Path <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP/Host
Port = (int)PortBox.Value,
UserName = UserBox.Text,
Password = PwdBox.Password, // <20><> PasswordBox <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
Name = finalName,
SourceType = sourceType,
IsRealTimeWatchEnabled = false
UriScheme = scheme,
UriHost = HostBox.Text.Trim(), // ȥ<><C8A5><EFBFBD><EFBFBD>β<EFBFBD>ո<EFBFBD>
UriPort = (int)PortBox.Value,
UriPath = PathBox.Text.Trim(),
UserName = UserBox.Text.Trim(),
Password = PwdBox.Password,
};
// <20><><EFBFBD><EFBFBD><E2B4A6>·<EFBFBD><C2B7><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><><D4B6>·<EFBFBD><C2B7><>ӵ<EFBFBD> Path <20><EFBFBD><EFA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֶδ<D6B6>
// Ϊ<>˼򵥣<CBBC><F2B5A5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> MediaFolder <20><><EFBFBD>
// <20><><EFBFBD><EFBFBD> MediaFolder <20><><EFBFBD><EFBFBD><EFBFBD>ټ<EFBFBD>һ<EFBFBD><D2BB> RemotePath <20>ֶΣ<D6B6><CEA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Path <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// *<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> MediaFolder <20><><EFBFBD><EFBFBD><E5A3AC><EFBFBD>ǿ<EFBFBD><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD>
// Path <20>ֶδ洢<CEB4><E6B4A2>ʽ<EFBFBD><CABD> "192.168.1.5/Music"
var rawPath = PathBox.Text.Trim().TrimStart('/', '\\'); // ȥ<><C8A5><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>б<EFBFBD><D0B1>
if (!string.IsNullOrEmpty(rawPath))
{
// <20>򵥵<EFBFBD>·<EFBFBD><C2B7>ƴ<EFBFBD><C6B4><EFBFBD>߼<EFBFBD>
if (sourceType == FileSourceType.SMB)
{
// SMBLibrary <20><><EFBFBD>߼<EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD> Host <20>ֿ<EFBFBD><D6BF><EFBFBD>ShareName <20>ֿ<EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP <20><><EFBFBD><EFBFBD> Path <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA> ShareName ƴ<>ں<EFBFBD><DABA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
// Ϊ<>˷<EFBFBD><CBB7><EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IP <20><> ShareName ƴ<><C6B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Path
// <20><><EFBFBD><EFBFBD>: 192.168.1.5/Music
folder.Path = $"{HostBox.Text}/{rawPath}";
}
else
{
// FTP/WebDAV: 192.168.1.5/pub/music
folder.Path = $"{HostBox.Text}/{rawPath}";
}
}
return folder;
}
public void ShowError(string message)
public void ShowError(string? message)
{
ErrorInfoBar.Message = message;
ErrorInfoBar.IsOpen = true;
ErrorInfoBar.IsOpen = !string.IsNullOrWhiteSpace(message);
}
public void SetProgressBarVisibility(Visibility visibility)
@@ -106,5 +145,53 @@ namespace BetterLyrics.WinUI3.Controls
ProgressBar.Visibility = visibility;
}
private void PathBox_TextChanged(object sender, TextChangedEventArgs e)
{
CheckPathForWarning();
}
private void CheckPathForWarning()
{
string? path = PathBox.Text?.Trim();
bool isSymbolRoot = string.IsNullOrEmpty(path) ||
path == "/" ||
path == "\\";
bool isDriveRoot = false;
if (!string.IsNullOrEmpty(path))
{
var normalized = path.TrimEnd('\\', '/');
isDriveRoot = normalized.EndsWith(":") && normalized.Length == 2;
}
bool isRoot = isSymbolRoot || isDriveRoot;
if (isRoot)
{
PathWarningBar.Message = _localizationService.GetLocalizedString("FileSystemServiceRootDirectoryWarning");
PathWarningBar.IsOpen = true;
}
else
{
PathWarningBar.IsOpen = false;
}
}
private async void BrowseButton_Click(object sender, RoutedEventArgs e)
{
try
{
var folder = await PickerHelper.PickSingleFolderAsync<SettingsWindow>();
if (folder != null)
{
PathBox.Text = folder.Path;
}
}
catch (Exception ex)
{
ShowError(ex.Message);
}
}
}
}

View File

@@ -1,6 +1,6 @@
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Hooks;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Input;
using Microsoft.UI.Xaml;
@@ -16,7 +16,7 @@ namespace BetterLyrics.WinUI3.Controls
{
public sealed partial class ShortcutTextBox : UserControl
{
private readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
public ShortcutTextBox()
{

View File

@@ -18,13 +18,7 @@
<TextBlock x:Uid="AppSettingsControlGeneral" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />
<dev:SettingsCard x:Uid="SettingsPageConfigName" HeaderIcon="{ui:FontIcon FontFamily={StaticResource IconFontFamily}, Glyph=&#xE8AC;}">
<StackPanel
Margin="0,6,0,0"
Orientation="Horizontal"
Spacing="6">
<TextBox Text="{x:Bind LyricsWindowStatus.Name, Mode=TwoWay}" TextWrapping="Wrap" />
<Button Content="{ui:FontIcon FontFamily={StaticResource IconFontFamily}, FontSize=12, Glyph=&#xE8FB;}" Style="{StaticResource GhostButtonStyle}" />
</StackPanel>
<TextBox Text="{x:Bind LyricsWindowStatus.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" />
</dev:SettingsCard>
<dev:SettingsExpander

View File

@@ -1,5 +1,5 @@
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Xaml.Data;
using System;
@@ -8,7 +8,7 @@ namespace BetterLyrics.WinUI3.Converter
{
public partial class AlbumArtSearchProviderToDisplayNameConverter : IValueConverter
{
private readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
public object Convert(object value, Type targetType, object parameter, string language)
{
@@ -16,8 +16,8 @@ namespace BetterLyrics.WinUI3.Converter
{
return provider switch
{
AlbumArtSearchProvider.Local => _resourceService.GetLocalizedString("AlbumArtSearchLocalProvider"),
AlbumArtSearchProvider.SMTC => _resourceService.GetLocalizedString("AlbumArtSearchSMTCProvider"),
AlbumArtSearchProvider.Local => _localizationService.GetLocalizedString("AlbumArtSearchLocalProvider"),
AlbumArtSearchProvider.SMTC => _localizationService.GetLocalizedString("AlbumArtSearchSMTCProvider"),
AlbumArtSearchProvider.iTunes => "iTunes",
_ => throw new Exception($"Unknown AlbumArtSearchProvider: {provider}"),
};

View File

@@ -17,20 +17,16 @@ namespace BetterLyrics.WinUI3.Converter
using (var ms = new MemoryStream(byteArray))
{
var stream = ms.AsRandomAccessStream();
var bitmapImage = new BitmapImage();
bitmapImage.SetSource(stream);
return bitmapImage;
}
}
catch
{
return PathHelper.AlbumArtPlaceholderPath;
}
catch { }
}
return PathHelper.AlbumArtPlaceholderPath;
return new BitmapImage(new Uri(PathHelper.AlbumArtPlaceholderPath));
}
public object ConvertBack(object value, Type targetType, object parameter, string language)

View File

@@ -11,7 +11,8 @@ namespace BetterLyrics.WinUI3.Converter
{
if (value is string langCode)
{
return LanguageHelper.SupportedDisplayLanguages.FindIndex(x => x.LanguageCode == langCode);
var found = LanguageHelper.SupportedDisplayLanguages.FindIndex(x => x.LanguageCode == langCode);
return found == -1 ? 0 : found;
}
return 0;
}

View File

@@ -1,9 +1,6 @@
using BetterLyrics.WinUI3.Enums;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Text;
namespace BetterLyrics.WinUI3.Converter
{
@@ -15,14 +12,14 @@ namespace BetterLyrics.WinUI3.Converter
{
return type switch
{
FileSourceType.Local => new FontIcon { Glyph = "\uE8B7" }, // Folder
FileSourceType.SMB => new FontIcon { Glyph = "\uE839" }, // Network
FileSourceType.FTP => new FontIcon { Glyph = "\uE838" }, // Globe
FileSourceType.WebDav => new FontIcon { Glyph = "\uE753" }, // Cloud
_ => new FontIcon { Glyph = "\uE8B7" }
FileSourceType.Local => "\uE8B7", // Folder
FileSourceType.SMB => "\uE839", // Network
FileSourceType.FTP => "\uE838", // Globe
FileSourceType.WebDav => "\uE753", // Cloud
_ => "\uE8B7"
};
}
return new FontIcon { Glyph = "\uE8B7" };
return "\uE8B7";
}
public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException();

View File

@@ -1,7 +1,7 @@
// 2025/6/23 by Zhe Fang
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Xaml.Data;
using System;
@@ -10,7 +10,7 @@ namespace BetterLyrics.WinUI3.Converter
{
public partial class LyricsSearchProviderToDisplayNameConverter : IValueConverter
{
private readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
public object Convert(object value, Type targetType, object parameter, string language)
{
@@ -24,10 +24,10 @@ namespace BetterLyrics.WinUI3.Converter
LyricsSearchProvider.Kugou => "酷狗音乐",
LyricsSearchProvider.AmllTtmlDb => "amll-ttml-db",
LyricsSearchProvider.AppleMusic => "Apple Music",
LyricsSearchProvider.LocalLrcFile => _resourceService.GetLocalizedString("LyricsSearchProviderLocalLrcFile"),
LyricsSearchProvider.LocalMusicFile => _resourceService.GetLocalizedString("LyricsSearchProviderLocalMusicFile"),
LyricsSearchProvider.LocalEslrcFile => _resourceService.GetLocalizedString("LyricsSearchProviderEslrcFile"),
LyricsSearchProvider.LocalTtmlFile => _resourceService.GetLocalizedString("LyricsSearchProviderTtmlFile"),
LyricsSearchProvider.LocalLrcFile => _localizationService.GetLocalizedString("LyricsSearchProviderLocalLrcFile"),
LyricsSearchProvider.LocalMusicFile => _localizationService.GetLocalizedString("LyricsSearchProviderLocalMusicFile"),
LyricsSearchProvider.LocalEslrcFile => _localizationService.GetLocalizedString("LyricsSearchProviderEslrcFile"),
LyricsSearchProvider.LocalTtmlFile => _localizationService.GetLocalizedString("LyricsSearchProviderTtmlFile"),
_ => "N/A",
};
}

View File

@@ -1,6 +1,7 @@
// 2025/6/23 by Zhe Fang
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
@@ -10,13 +11,13 @@ namespace BetterLyrics.WinUI3.Converter
{
public partial class MatchedLocalFilesPathToVisibilityConverter : IValueConverter
{
private readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is string path)
{
if (path == _resourceService.GetLocalizedString("MainPageNoLocalFilesMatched"))
if (path == _localizationService.GetLocalizedString("MainPageNoLocalFilesMatched"))
{
return Visibility.Collapsed;
}

View File

@@ -3,7 +3,7 @@ using System;
namespace BetterLyrics.WinUI3.Converter
{
public class MillisecondsToSecondsConverter : IValueConverter
public partial class MillisecondsToSecondsConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{

View File

@@ -0,0 +1,31 @@
using BetterLyrics.WinUI3.Helper;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media.Imaging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace BetterLyrics.WinUI3.Converter
{
public partial class PathToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
string targetPath = PathHelper.AlbumArtPlaceholderPath;
if (value is string path)
{
if (File.Exists(path))
{
targetPath = path;
}
}
return new BitmapImage(new Uri(targetPath));
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
}

View File

@@ -1,7 +1,7 @@
// 2025/6/23 by Zhe Fang
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Xaml.Data;
using System;
@@ -10,7 +10,7 @@ namespace BetterLyrics.WinUI3.Converter
{
public partial class TranslationSearchProviderToDisplayNameConverter : IValueConverter
{
private readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
public object Convert(object value, Type targetType, object parameter, string language)
{
@@ -24,10 +24,10 @@ namespace BetterLyrics.WinUI3.Converter
TranslationSearchProvider.Kugou => "酷狗音乐",
TranslationSearchProvider.AmllTtmlDb => "amll-ttml-db",
TranslationSearchProvider.AppleMusic => "Apple Music",
TranslationSearchProvider.LocalLrcFile => _resourceService.GetLocalizedString("LyricsSearchProviderLocalLrcFile"),
TranslationSearchProvider.LocalMusicFile => _resourceService.GetLocalizedString("LyricsSearchProviderLocalMusicFile"),
TranslationSearchProvider.LocalEslrcFile => _resourceService.GetLocalizedString("LyricsSearchProviderEslrcFile"),
TranslationSearchProvider.LocalTtmlFile => _resourceService.GetLocalizedString("LyricsSearchProviderTtmlFile"),
TranslationSearchProvider.LocalLrcFile => _localizationService.GetLocalizedString("LyricsSearchProviderLocalLrcFile"),
TranslationSearchProvider.LocalMusicFile => _localizationService.GetLocalizedString("LyricsSearchProviderLocalMusicFile"),
TranslationSearchProvider.LocalEslrcFile => _localizationService.GetLocalizedString("LyricsSearchProviderEslrcFile"),
TranslationSearchProvider.LocalTtmlFile => _localizationService.GetLocalizedString("LyricsSearchProviderTtmlFile"),
TranslationSearchProvider.LibreTranslate => "LibreTranslate",
_ => "N/A",
};

View File

@@ -1,5 +1,5 @@
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Xaml.Data;
using System;
@@ -8,7 +8,7 @@ namespace BetterLyrics.WinUI3.Converter
{
public partial class TransliterationSearchProviderToDisplayNameConverter : IValueConverter
{
private readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
public object Convert(object value, Type targetType, object parameter, string language)
{
@@ -22,10 +22,10 @@ namespace BetterLyrics.WinUI3.Converter
TransliterationSearchProvider.Kugou => "酷狗音乐",
TransliterationSearchProvider.AmllTtmlDb => "amll-ttml-db",
TransliterationSearchProvider.AppleMusic => "Apple Music",
TransliterationSearchProvider.LocalLrcFile => _resourceService.GetLocalizedString("LyricsSearchProviderLocalLrcFile"),
TransliterationSearchProvider.LocalMusicFile => _resourceService.GetLocalizedString("LyricsSearchProviderLocalMusicFile"),
TransliterationSearchProvider.LocalEslrcFile => _resourceService.GetLocalizedString("LyricsSearchProviderEslrcFile"),
TransliterationSearchProvider.LocalTtmlFile => _resourceService.GetLocalizedString("LyricsSearchProviderTtmlFile"),
TransliterationSearchProvider.LocalLrcFile => _localizationService.GetLocalizedString("LyricsSearchProviderLocalLrcFile"),
TransliterationSearchProvider.LocalMusicFile => _localizationService.GetLocalizedString("LyricsSearchProviderLocalMusicFile"),
TransliterationSearchProvider.LocalEslrcFile => _localizationService.GetLocalizedString("LyricsSearchProviderEslrcFile"),
TransliterationSearchProvider.LocalTtmlFile => _localizationService.GetLocalizedString("LyricsSearchProviderTtmlFile"),
TransliterationSearchProvider.BetterLyrics => "BetterLyrics",
TransliterationSearchProvider.CutletDocker => "cutlet-docker",
_ => "N/A",

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BetterLyrics.WinUI3.Enums
{
public enum AutoScanInterval
{
Disabled,
Every15Minutes,
EveryHour,
Every6Hours,
Daily
}
}

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BetterLyrics.WinUI3.Enums
namespace BetterLyrics.WinUI3.Enums
{
public enum FileSourceType
{

View File

@@ -0,0 +1,123 @@
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BetterLyrics.WinUI3.Extensions
{
public static class LyricsDataExtensions
{
extension(LyricsData lyricsData)
{
public static LyricsData GetLoadingPlaceholder()
{
return new LyricsData()
{
LyricsLines = [
new LyricsLine
{
StartMs = 0,
EndMs = (int)TimeSpan.FromMinutes(99).TotalMilliseconds,
OriginalText = "● ● ●",
},
],
LanguageCode = "N/A",
};
}
public void SetTranslatedText(LyricsData translationData, int toleranceMs = 50)
{
foreach (var line in lyricsData.LyricsLines)
{
// 在翻译歌词中查找与当前行开始时间最接近且在容忍范围内的行
var transLine = translationData.LyricsLines
.FirstOrDefault(t => Math.Abs(t.StartMs - line.StartMs) <= toleranceMs);
if (transLine != null)
{
// 此处 transLine.OriginalText 指翻译中的“原文”属性
line.TranslatedText = transLine.OriginalText;
}
else
{
// 没有匹配的翻译
line.TranslatedText = "";
}
}
}
public void SetPhoneticText(LyricsData phoneticData, int toleranceMs = 50)
{
foreach (var line in lyricsData.LyricsLines)
{
// 在音译歌词中查找与当前行开始时间最接近且在容忍范围内的行
var transLine = phoneticData.LyricsLines
.FirstOrDefault(t => Math.Abs(t.StartMs - line.StartMs) <= toleranceMs);
if (transLine != null)
{
// 此处 transLine.OriginalText 指音译中的“原文”属性
line.PhoneticText = transLine.OriginalText;
}
else
{
// 没有匹配的音译
line.PhoneticText = "";
}
}
}
public void SetTranslation(string translation)
{
List<string> translationArr = translation.Split(StringHelper.NewLine).ToList();
int i = 0;
foreach (var line in lyricsData.LyricsLines)
{
if (i >= translationArr.Count)
{
line.TranslatedText = ""; // No translation available, keep empty
}
else
{
line.TranslatedText = translationArr[i];
}
i++;
}
}
public void SetTransliteration(string transliteration)
{
List<string> transliterationArr = transliteration.Split(StringHelper.NewLine).ToList();
int i = 0;
foreach (var line in lyricsData.LyricsLines)
{
if (i >= transliterationArr.Count)
{
line.PhoneticText = ""; // No transliteration available, keep empty
}
else
{
line.PhoneticText = transliterationArr[i];
}
i++;
}
}
public LyricsLine? GetLyricsLine(double sec)
{
for (int i = 0; i < lyricsData.LyricsLines.Count; i++)
{
var line = lyricsData.LyricsLines[i];
if (line.StartMs > sec * 1000)
{
return lyricsData.LyricsLines.ElementAtOrDefault(i - 1);
}
}
return null;
}
}
}
}

View File

@@ -2,7 +2,7 @@
using BetterLyrics.WinUI3.Hooks;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Models.Settings;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using BetterLyrics.WinUI3.Views;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Xaml;
@@ -12,14 +12,14 @@ namespace BetterLyrics.WinUI3.Extensions
{
public static class LyricsWindowStatusExtensions
{
private static readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private static readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
public static LyricsWindowStatus DesktopMode(Window? window = null)
{
window ??= WindowHook.GetWindow<SystemTrayWindow>();
return new LyricsWindowStatus(window)
{
Name = _resourceService.GetLocalizedString("DesktopMode"),
Name = _localizationService.GetLocalizedString("DesktopMode"),
LyricsDisplayType = LyricsDisplayType.LyricsOnly,
WindowBounds = new Rect(100, 100, 600, 250),
IsLocked = true,
@@ -44,7 +44,7 @@ namespace BetterLyrics.WinUI3.Extensions
window ??= WindowHook.GetWindow<SystemTrayWindow>();
var status = new LyricsWindowStatus(window)
{
Name = _resourceService.GetLocalizedString("DockedMode"),
Name = _localizationService.GetLocalizedString("DockedMode"),
IsWorkArea = true,
IsAlwaysOnTop = true,
IsAlwaysOnTopPolling = true,
@@ -71,7 +71,7 @@ namespace BetterLyrics.WinUI3.Extensions
window ??= WindowHook.GetWindow<SystemTrayWindow>();
var status = new LyricsWindowStatus(window)
{
Name = _resourceService.GetLocalizedString("FullscreenMode"),
Name = _localizationService.GetLocalizedString("FullscreenMode"),
LyricsLayoutOrientation = LyricsLayoutOrientation.Vertical,
LyricsStyleSettings = new LyricsStyleSettings
{
@@ -93,7 +93,7 @@ namespace BetterLyrics.WinUI3.Extensions
window ??= WindowHook.GetWindow<SystemTrayWindow>();
return new LyricsWindowStatus(window)
{
Name = _resourceService.GetLocalizedString("StandardMode"),
Name = _localizationService.GetLocalizedString("StandardMode"),
};
}
@@ -102,7 +102,7 @@ namespace BetterLyrics.WinUI3.Extensions
window ??= WindowHook.GetWindow<SystemTrayWindow>();
return new LyricsWindowStatus(window)
{
Name = _resourceService.GetLocalizedString("NarrowMode"),
Name = _localizationService.GetLocalizedString("NarrowMode"),
WindowBounds = new Rect(100, 100, 400, 800),
LyricsLayoutOrientation = LyricsLayoutOrientation.Vertical,
};
@@ -113,7 +113,7 @@ namespace BetterLyrics.WinUI3.Extensions
window ??= WindowHook.GetWindow<SystemTrayWindow>();
return new LyricsWindowStatus(window)
{
Name = _resourceService.GetLocalizedString("TaskbarMode"),
Name = _localizationService.GetLocalizedString("TaskbarMode"),
LyricsDisplayType = LyricsDisplayType.LyricsOnly,
IsPinToTaskbar = true,
IsLocked = true,

View File

@@ -1,6 +1,6 @@
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
@@ -9,16 +9,24 @@ namespace BetterLyrics.WinUI3.Extensions
{
public static class WindowExtensions
{
private static readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private static readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
extension(Window window)
{
public void Init(
string titleKey,
string titleKey = "",
string title = "",
TitleBarHeightOption titleBarHeightOption = TitleBarHeightOption.Standard,
BackdropType backdropType = BackdropType.DesktopAcrylic)
{
window.Title = _resourceService.GetLocalizedString(titleKey);
if (titleKey != "")
{
window.Title = _localizationService.GetLocalizedString(titleKey);
}
if (title != "")
{
window.Title = title;
}
window.AppWindow.TitleBar.PreferredTheme = TitleBarTheme.UseDefaultAppMode;
window.AppWindow.SetIcons();

View File

@@ -5,7 +5,9 @@ using BetterLyrics.WinUI3.Extensions;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Serialization;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Ude;
@@ -86,5 +88,15 @@ namespace BetterLyrics.WinUI3.Helper
".wav", ".aiff", ".aif", ".pcm", ".cda", ".dsf", ".dff", ".au", ".snd",
".mid", ".midi", ".mod", ".xm", ".it", ".s3m"
};
public static readonly string[] LyricExtensions =
Enum.GetValues(typeof(LyricsSearchProvider)).Cast<LyricsSearchProvider>()
.Where(x => x.IsLocal())
.Select(x => x.GetLyricsFormat())
.Where(x => x != LyricsFormat.NotSpecified)
.Select(x => x.ToFileExtension())
.ToArray();
public static readonly HashSet<string> AllSupportedExtensions = new(MusicExtensions.Union(LyricExtensions));
}
}

View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
using BetterLyrics.WinUI3.Models;
public static class FolderTreeBuilder
{
public static ObservableCollection<FolderNode> Build(List<ExtendedTrack> tracks, List<MediaFolder> folderConfigs)
{
var rootNodes = new ObservableCollection<FolderNode>();
// 按 MediaFolderId 分组
var folderGroups = tracks.GroupBy(t => t.MediaFolderId);
foreach (var group in folderGroups)
{
var config = folderConfigs.FirstOrDefault(f => f.Id == group.Key);
if (config == null) continue;
string baseUri = config.GetStandardUri().AbsoluteUri.TrimEnd('/');
var rootNode = new FolderNode
{
SourceType = config.SourceType,
FolderName = config.Name ?? config.ConnectionSummary, // 显示用户自定义的名字
MediaFolderId = group.Key,
FolderPath = baseUri,
IsExpanded = true
};
foreach (var track in group)
{
try
{
if (!track.Uri.StartsWith(baseUri)) continue; // 防御性编程
string relativePart = track.Uri.Substring(baseUri.Length);
var segments = relativePart
.Split('/', StringSplitOptions.RemoveEmptyEntries)
.Select(s => System.Net.WebUtility.UrlDecode(s))
.ToArray();
if (segments.Length > 1) // 长度大于1说明在子文件夹里
{
var folderSegments = segments.Take(segments.Length - 1).ToArray();
CreateFolderStructure(rootNode, folderSegments, baseUri);
}
}
catch { }
}
rootNodes.Add(rootNode);
}
return rootNodes;
}
private static void CreateFolderStructure(FolderNode parent, string[] segments, string rootBaseUri)
{
var current = parent;
string currentFullPath = parent.FolderPath;
foreach (var segmentName in segments)
{
var existingChild = current.SubFolders.FirstOrDefault(f => f.FolderName == segmentName);
currentFullPath += "/" + System.Net.WebUtility.UrlEncode(segmentName);
if (existingChild == null)
{
var newFolder = new FolderNode
{
FolderName = segmentName,
FolderPath = currentFullPath, // 存完整的 URI
MediaFolderId = parent.MediaFolderId
};
current.SubFolders.Add(newFolder);
current = newFolder;
}
else
{
current = existingChild;
currentFullPath = existingChild.FolderPath;
}
}
}
}

View File

@@ -1,8 +1,6 @@
using Microsoft.Graphics.Canvas.Text;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Documents;
using System.Windows.Markup;
using System.Windows.Media;

View File

@@ -1,8 +1,10 @@
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using CommunityToolkit.Mvvm.DependencyInjection;
using NTextCat;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using Windows.Globalization;
@@ -10,9 +12,9 @@ namespace BetterLyrics.WinUI3.Helper
{
public class LanguageHelper
{
private static readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
private static readonly RankedLanguageIdentifierFactory _factory = new();
private static readonly RankedLanguageIdentifier _identifier;
private static readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
public const string ChineseCode = "zh";
public const string JapaneseCode = "ja";
@@ -92,12 +94,23 @@ namespace BetterLyrics.WinUI3.Helper
public static List<ExtendedLanguage> SupportedDisplayLanguages { get; set; } =
[
new ExtendedLanguage("", _resourceService.GetLocalizedString("SettingsPageSystemLanguage")),
new ExtendedLanguage("en-US", "English"),
new ExtendedLanguage("ja-JP"),
new ExtendedLanguage("ko-KR"),
new ExtendedLanguage("zh-CN", "简体中文"),
new ExtendedLanguage("zh-TW", "繁體中文"),
new ExtendedLanguage(CultureInfo.CurrentUICulture.Name, _localizationService.GetLocalizedString("SettingsPageSystemLanguage")),
new ExtendedLanguage("ar"),
new ExtendedLanguage("de"),
new ExtendedLanguage("en"),
new ExtendedLanguage("es"),
new ExtendedLanguage("fr"),
new ExtendedLanguage("hi"),
new ExtendedLanguage("id"),
new ExtendedLanguage("ja"),
new ExtendedLanguage("ko"),
new ExtendedLanguage("ms"),
new ExtendedLanguage("pt"),
new ExtendedLanguage("ru"),
new ExtendedLanguage("th"),
new ExtendedLanguage("vi"),
new ExtendedLanguage("zh-Hans"),
new ExtendedLanguage("zh-Hant"),
];
static LanguageHelper()

View File

@@ -54,8 +54,10 @@ namespace BetterLyrics.WinUI3.Helper
public static string AlbumArtCacheDirectory => Path.Combine(CacheFolder, "album-art");
public static string iTunesAlbumArtCacheDirectory => Path.Combine(AlbumArtCacheDirectory, "itunes");
public static string LocalAlbumArtCacheDirectory => Path.Combine(AlbumArtCacheDirectory, "local");
public static string PlayQueuePath => Path.Combine(CacheFolder, "play-queue.m3u");
public static string FilesCachePath => Path.Combine(CacheFolder, "files_cache.db");
public static void EnsureDirectories()
{
@@ -75,6 +77,7 @@ namespace BetterLyrics.WinUI3.Helper
Directory.CreateDirectory(LocalTtmlCacheDirectory);
Directory.CreateDirectory(iTunesAlbumArtCacheDirectory);
Directory.CreateDirectory(LocalAlbumArtCacheDirectory);
}
}
}

View File

@@ -1,4 +1,4 @@
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using CommunityToolkit.Mvvm.DependencyInjection;
using System;
@@ -6,7 +6,7 @@ namespace BetterLyrics.WinUI3.Helper
{
public static class PhoneticHelper
{
private static readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private static readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
public const string PinyinCode = "zh-cmn-pinyin";
public const string JyutpingCode = "zh-yue-jyutping";
@@ -22,11 +22,11 @@ namespace BetterLyrics.WinUI3.Helper
switch (code)
{
case PinyinCode:
return _resourceService.GetLocalizedString("Pinyin");
return _localizationService.GetLocalizedString("Pinyin");
case JyutpingCode:
return _resourceService.GetLocalizedString("Jyutping");
return _localizationService.GetLocalizedString("Jyutping");
case RomanCode:
return _resourceService.GetLocalizedString("Romaji");
return _localizationService.GetLocalizedString("Romaji");
default:
throw new ArgumentOutOfRangeException(nameof(code));
}

View File

@@ -1,6 +1,5 @@
using BetterLyrics.WinUI3.Hooks;
using DevWinUI;
using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

View File

@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace BetterLyrics.WinUI3.Models.FileSystem
namespace BetterLyrics.WinUI3.Helper
{
public class StreamFileAbstraction : TagLib.File.IFileAbstraction
{
@@ -11,7 +9,7 @@ namespace BetterLyrics.WinUI3.Models.FileSystem
private readonly Stream _stream;
private readonly bool _closeStreamOnDispose;
public StreamFileAbstraction(string path, Stream stream, bool closeStreamOnDispose = false)
public StreamFileAbstraction(string path, Stream? stream, bool closeStreamOnDispose = false)
{
_name = Path.GetFileName(path);
_stream = stream ?? throw new ArgumentNullException(nameof(stream));

View File

@@ -1,4 +1,4 @@
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Windows.AppNotifications;
@@ -8,12 +8,12 @@ namespace BetterLyrics.WinUI3.Helper
{
public class ToastHelper
{
private static readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private static readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
public static void ShowToast(string localizedTitleKey, string? description, InfoBarSeverity severity)
{
AppNotification notification = new AppNotificationBuilder()
.AddText(_resourceService.GetLocalizedString(localizedTitleKey))
.AddText(_localizationService.GetLocalizedString(localizedTitleKey))
.AddText(description)
.BuildNotification();

View File

@@ -7,6 +7,7 @@ using FlaUI.Core.EventHandlers;
using FlaUI.UIA3;
using Microsoft.UI.Dispatching;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
@@ -186,7 +187,8 @@ namespace BetterLyrics.WinUI3.Hooks
if (width < 20) return Rectangle.Empty;
return new Rectangle(finalLeft, taskbarRect.Top, width, taskbarRect.Height);
var finalRect = new Rectangle(finalLeft, taskbarRect.Top, width, taskbarRect.Height);
return finalRect;
}
catch (Exception ex)
{

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;
namespace BetterLyrics.WinUI3.Models
{

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
using System.Text.Json.Serialization;
namespace BetterLyrics.WinUI3.Models
{

View File

@@ -1,30 +1,215 @@
using BetterLyrics.WinUI3.Models.FileSystem;
using ATL;
using BetterLyrics.WinUI3.Helper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Linq;
namespace BetterLyrics.WinUI3.Models
{
public class ExtendedTrack : ATL.Track
public class ExtendedTrack
{
public new string Path { get; private set; } = "";
public string RawLyrics { get; set; } = "";
public string ParentFolderName => Directory.GetParent(Path)?.Name ?? "";
public string ParentFolderPath => Directory.GetParent(Path)?.FullName ?? "";
public string FileName => System.IO.Path.GetFileName(Path);
public string Uri { get; private set; } = "";
public string DecodedAbsoluteUri
{
get
{
if (string.IsNullOrEmpty(Uri)) return "";
try
{
var u = new Uri(Uri);
return u.IsFile ? u.LocalPath : System.Net.WebUtility.UrlDecode(u.AbsoluteUri);
}
catch { return Uri; }
}
}
public string? RawLyrics { get; set; }
public string? LocalAlbumArtPath { get; set; }
public byte[]? AlbumArtByteArray { get; set; }
public string ParentFolderName
{
get
{
if (string.IsNullOrEmpty(Uri)) return "";
try
{
// 使用 Uri Segments 安全获取倒数第二层 (文件夹名)
// Segments 示例: "/", "Music/", "Artist/", "Song.mp3"
var u = new System.Uri(Uri);
if (u.Segments.Length > 1)
{
// 取倒数第二个 segment (如果是文件)
// 注意处理末尾斜杠
string folder = u.Segments[u.Segments.Length - 2];
return System.Net.WebUtility.UrlDecode(folder.TrimEnd('/', '\\'));
}
return "";
}
catch
{
return "";
}
}
}
public string ParentFolderPath
{
get
{
if (string.IsNullOrEmpty(Uri)) return "";
try
{
var u = new System.Uri(Uri);
if (u.IsFile)
{
// 本地文件:返回目录路径 C:\Music
return System.IO.Path.GetDirectoryName(u.LocalPath) ?? "";
}
else
{
// 远程文件:返回去掉文件名的 URI
// new Uri(u, ".") 表示当前目录
return new System.Uri(u, ".").AbsoluteUri;
}
}
catch
{
return "";
}
}
}
public string FileName
{
get
{
if (string.IsNullOrEmpty(Uri)) return "";
try
{
var u = new System.Uri(Uri);
if (u.IsFile) return System.IO.Path.GetFileName(u.LocalPath);
// 远程文件:获取 AbsolutePath 的最后一段并解码
// 例如: /Music/My%20Song.mp3 -> My Song.mp3
string rawName = System.IO.Path.GetFileName(u.AbsolutePath);
return System.Net.WebUtility.UrlDecode(rawName);
}
catch
{
return System.IO.Path.GetFileName(Uri);
}
}
}
public string MediaFolderId { get; set; } = "";
public string Title { get; set; } = "";
public string Artist { get; set; } = "";
public string Album { get; set; } = "";
public int? Year { get; set; }
public int Bitrate { get; set; }
public double SampleRate { get; set; }
public int BitDepth { get; set; }
public int Duration { get; set; }
public string AudioFormatName { get; set; } = "";
public string AudioFormatShortName { get; set; } = "";
public string Encoder { get; set; } = "";
public ExtendedTrack() : base() { }
public ExtendedTrack(string path) : base(path)
public ExtendedTrack(string uriString) : base()
{
Path = path;
Uri = uriString;
string atlPath = uriString;
try
{
var u = new Uri(uriString);
if (u.IsFile) atlPath = u.LocalPath;
}
catch { }
// 用于本地文件
var track = new Track(atlPath);
SetFromTrack(track);
}
public ExtendedTrack(string path, Stream stream) : base(stream, System.IO.Path.GetExtension(path))
public ExtendedTrack(FileCacheEntity? entity, Stream? stream = null) : base()
{
Path = path;
SetRawLyrics(new StreamFileAbstraction(path, stream));
if (entity == null) return;
this.MediaFolderId = entity.MediaFolderId;
this.Uri = entity.Uri;
this.Title = entity.Title;
this.Artist = entity.Artists;
this.Album = entity.Album;
this.Year = entity.Year;
this.Bitrate = entity.Bitrate;
this.SampleRate = entity.SampleRate;
this.BitDepth = entity.BitDepth;
this.Duration = entity.Duration;
this.AudioFormatName = entity.AudioFormatName;
this.AudioFormatShortName = entity.AudioFormatShortName;
this.Encoder = entity.Encoder;
this.RawLyrics = entity.EmbeddedLyrics;
this.LocalAlbumArtPath = entity.LocalAlbumArtPath;
if (stream != null)
{
var track = new Track(stream, Path.GetExtension(FileName));
SetFromTrack(track);
SetRawLyrics(new StreamFileAbstraction(Uri, stream));
}
}
private void SetFromTrack(Track? track)
{
if (track == null) return;
this.Title = track.Title;
this.Artist = track.Artist;
this.Album = track.Album;
this.Year = track.Year;
this.Bitrate = track.Bitrate;
this.SampleRate = track.SampleRate;
this.BitDepth = track.BitDepth;
this.Duration = track.Duration;
this.AudioFormatName = track.AudioFormat.Name;
this.AudioFormatShortName = track.AudioFormat.ShortName;
this.Encoder = track.Encoder;
this.AlbumArtByteArray = null;
if (track.EmbeddedPictures != null && track.EmbeddedPictures.Count > 0)
{
try
{
var validPics = track.EmbeddedPictures.Where(p => p != null).ToList();
if (validPics.Count > 0)
{
var cover = validPics.FirstOrDefault(p => p.PicType == PictureInfo.PIC_TYPE.Front);
if (cover == null)
{
cover = validPics.First();
}
this.AlbumArtByteArray = cover.PictureData;
}
}
catch (Exception) { }
}
}
private void SetRawLyrics(StreamFileAbstraction streamFileAbstraction)
@@ -36,4 +221,4 @@ namespace BetterLyrics.WinUI3.Models
catch (Exception) { }
}
}
}
}

View File

@@ -0,0 +1,57 @@
using SQLite;
using System;
namespace BetterLyrics.WinUI3.Models
{
[Table("FileCache")]
public class FileCacheEntity
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
// 【新增】关键字段!
// 关联到 MediaFolder.Id。
// 作用:
// 1. 区分不同配置(即使两个配置连的是同一个 SMB但在 APP 里视为不同源)。
// 2. 删除配置时,可以由 MediaFolderId 快速级联删除所有缓存。
[Indexed]
public string MediaFolderId { get; set; }
// 【修改】从 ParentPath 改为 ParentUri
// 存储父文件夹的标准 URI (smb://host/share/parent)
// 根目录文件的 ParentUri 可以为空,或者等于 MediaFolder 的 Base Uri
[Indexed]
public string? ParentUri { get; set; }
// 【核心】标准化的完整 URI (smb://host/share/folder/file.ext)
// 确保它是 URL 编码过且格式统一的
[Indexed(Unique = true)]
public string Uri { get; set; }
public string FileName { get; set; } = "";
public bool IsDirectory { get; set; }
// 记录文件大小,同步时用来对比文件是否变化
public long FileSize { get; set; }
// 记录修改时间,同步时对比使用
public DateTime? LastModified { get; set; }
// ------ 元数据部分 (保持不变) ------
public string Title { get; set; } = "";
public string Artists { get; set; } = "";
public string Album { get; set; } = "";
public int? Year { get; set; }
public int Bitrate { get; set; }
public double SampleRate { get; set; }
public int BitDepth { get; set; }
public int Duration { get; set; }
public string AudioFormatName { get; set; } = "";
public string AudioFormatShortName { get; set; } = "";
public string Encoder { get; set; } = "";
public string? EmbeddedLyrics { get; set; }
public string? LocalAlbumArtPath { get; set; }
public bool IsMetadataParsed { get; set; }
}
}

View File

@@ -1,55 +0,0 @@
using FluentFTP;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Models.FileSystem
{
public partial class FTPFileSystem : IUnifiedFileSystem
{
private readonly AsyncFtpClient _client;
private readonly string _rootPath; // 服务器上的根路径 (例如 /pub/music)
public FTPFileSystem(string host, string user, string pass, int port, string remotePath)
{
// 如果 path 是 "192.168.1.5/Music",我们需要把 /Music 拆出来
// 但为了简单,假设 host 仅仅是 IPremotePath 才是路径
_rootPath = remotePath ?? "/";
var config = new FtpConfig { ConnectTimeout = 5000 };
_client = new AsyncFtpClient(host, user ?? "anonymous", pass ?? "", port > 0 ? port : 21, config);
}
public async Task<bool> ConnectAsync()
{
await _client.AutoConnect();
return _client.IsConnected;
}
public async Task<List<UnifiedFileItem>> GetFilesAsync(string relativePath)
{
string targetPath = Path.Combine(_rootPath, relativePath).Replace("\\", "/");
var items = await _client.GetListing(targetPath);
return items.Select(i => new UnifiedFileItem
{
Name = i.Name,
FullPath = i.FullName,
IsFolder = i.Type == FtpObjectType.Directory,
Size = i.Size,
LastModified = i.Modified
}).ToList();
}
public async Task<Stream> OpenReadAsync(string fullPath)
{
return await _client.OpenRead(fullPath);
}
public async Task DisconnectAsync() => await _client.Disconnect();
public void Dispose() => _client?.Dispose();
}
}

View File

@@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
namespace BetterLyrics.WinUI3.Models.FileSystem
{
public interface IUnifiedFileSystem : IDisposable
{
Task<bool> ConnectAsync();
Task<List<UnifiedFileItem>> GetFilesAsync(string relativePath);
Task<Stream> OpenReadAsync(string fullPath);
Task DisconnectAsync();
}
}

View File

@@ -1,58 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Models.FileSystem
{
public partial class LocalFileSystem : IUnifiedFileSystem
{
private readonly string _rootPath;
public LocalFileSystem(string rootPath)
{
_rootPath = rootPath;
}
public Task<bool> ConnectAsync()
{
return Task.FromResult(Directory.Exists(_rootPath));
}
public async Task<List<UnifiedFileItem>> GetFilesAsync(string relativePath)
{
var result = new List<UnifiedFileItem>();
var targetPath = string.IsNullOrWhiteSpace(relativePath)
? _rootPath
: Path.Combine(_rootPath, relativePath);
if (!Directory.Exists(targetPath)) return result;
var dirInfo = new DirectoryInfo(targetPath);
foreach (var item in dirInfo.GetFileSystemInfos())
{
bool isDir = (item.Attributes & FileAttributes.Directory) == FileAttributes.Directory;
result.Add(new UnifiedFileItem
{
Name = item.Name,
FullPath = item.FullName,
IsFolder = isDir,
Size = isDir ? 0 : ((FileInfo)item).Length,
LastModified = item.LastWriteTime
});
}
return result;
}
public async Task<Stream> OpenReadAsync(string fullPath)
{
return new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
}
public async Task DisconnectAsync() => await Task.CompletedTask;
public void Dispose() { }
}
}

View File

@@ -1,131 +0,0 @@
using SMBLibrary;
using SMBLibrary.Client;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Models.FileSystem
{
public partial class SMBFileSystem : IUnifiedFileSystem
{
private SMB2Client _client;
private ISMBFileStore _fileStore;
private readonly string _ip;
private readonly string _shareName;
private readonly string _pathInsideShare; // 共享里的子路径
private readonly string _username;
private readonly string _password;
// fullPathInput 例如: "192.168.1.5/Music/Pop"
public SMBFileSystem(string fullPathInput, string user, string pass)
{
_username = user;
_password = pass;
// 解析路径:分离 IP 和 共享名
var parts = fullPathInput.Replace("\\", "/").Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length >= 1) _ip = parts[0];
if (parts.Length >= 2) _shareName = parts[1];
// 剩下的部分重新拼起来作为子路径
if (parts.Length > 2)
_pathInsideShare = string.Join("\\", parts.Skip(2));
else
_pathInsideShare = "";
}
public async Task<bool> ConnectAsync()
{
_client = new SMB2Client();
bool connected = _client.Connect(_ip, SMBTransportType.DirectTCPTransport);
if (!connected) return false;
var status = _client.Login(string.Empty, _username, _password);
if (status != NTStatus.STATUS_SUCCESS) return false;
// 连接具体的共享文件夹
if (string.IsNullOrEmpty(_shareName)) return true; // 只连了服务器,没连共享
_fileStore = _client.TreeConnect(_shareName, out status);
return status == NTStatus.STATUS_SUCCESS;
}
public async Task<List<UnifiedFileItem>> GetFilesAsync(string relativePath)
{
var result = new List<UnifiedFileItem>();
if (_fileStore == null) return result;
// 拼接完整路径: Root里面的子路径 + 传入的相对路径
string queryPath = Path.Combine(_pathInsideShare, relativePath).Replace("/", "\\").TrimStart('\\');
// 打开目录
var statusRet = _fileStore.CreateFile(out object handle, out FileStatus status, queryPath,
AccessMask.GENERIC_READ, SMBLibrary.FileAttributes.Directory, ShareAccess.Read,
CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);
if (statusRet != NTStatus.STATUS_SUCCESS) return result;
List<QueryDirectoryFileInformation> fileInfo;
do
{
statusRet = _fileStore.QueryDirectory(out fileInfo, handle, "*", FileInformationClass.FileDirectoryInformation);
List<FileDirectoryInformation> list = fileInfo.Select(x => (FileDirectoryInformation)x).ToList();
foreach (var item in list)
{
// 排除当前目录和父目录
if (item.FileName == "." || item.FileName == "..") continue;
result.Add(new UnifiedFileItem
{
Name = item.FileName,
FullPath = Path.Combine(queryPath, item.FileName),
IsFolder = (item.FileAttributes & SMBLibrary.FileAttributes.Directory) == SMBLibrary.FileAttributes.Directory,
Size = item.AllocationSize,
LastModified = item.LastWriteTime
});
}
if (statusRet == NTStatus.STATUS_NO_MORE_FILES)
{
break;
}
if (statusRet != NTStatus.STATUS_SUCCESS)
{
// Log
break;
}
} while (statusRet == NTStatus.STATUS_SUCCESS);
_fileStore.CloseFile(handle);
return result;
}
public async Task<Stream> OpenReadAsync(string fullPath)
{
var ret = _fileStore.CreateFile(out object handle, out FileStatus status, fullPath,
AccessMask.GENERIC_READ | AccessMask.SYNCHRONIZE, 0, ShareAccess.Read, CreateDisposition.FILE_OPEN, 0, null);
if (ret != NTStatus.STATUS_SUCCESS) throw new IOException($"SMB Open Error: {ret}");
return new SMBReadOnlyStream(_fileStore, handle);
}
public async Task DisconnectAsync()
{
_client?.Disconnect();
await Task.CompletedTask;
}
public void Dispose()
{
_client?.Disconnect();
}
}
}

View File

@@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BetterLyrics.WinUI3.Models.FileSystem
{
public class UnifiedFileItem
{
public string Name { get; set; }
public string FullPath { get; set; }
public long Size { get; set; }
public bool IsFolder { get; set; }
public DateTime? LastModified { get; set; }
}
}

View File

@@ -1,87 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebDav;
namespace BetterLyrics.WinUI3.Models.FileSystem
{
public partial class WebDavFileSystem : IUnifiedFileSystem
{
private readonly WebDavClient _client;
private readonly string _baseUrl;
private readonly string _rootPath;
// host: http://192.168.1.5:5005
// path: /music
public WebDavFileSystem(string host, string user, string pass, int port, string path)
{
if (!host.StartsWith("http")) host = $"http://{host}";
if (port > 0) host = $"{host}:{port}";
_baseUrl = host;
_rootPath = path ?? "/";
_client = new WebDavClient(new WebDavClientParams
{
BaseAddress = new Uri(_baseUrl),
Credentials = new System.Net.NetworkCredential(user, pass)
});
}
public async Task<bool> ConnectAsync()
{
// WebDAV 无状态Propfind 测试根目录连通性
var result = await _client.Propfind(_rootPath);
return result.IsSuccessful;
}
public async Task<List<UnifiedFileItem>> GetFilesAsync(string relativePath)
{
var targetPath = Path.Combine(_rootPath, relativePath).Replace("\\", "/");
var result = await _client.Propfind(targetPath);
var list = new List<UnifiedFileItem>();
if (result.IsSuccessful)
{
foreach (var res in result.Resources)
{
if (res == null || res.Uri == null) continue;
// 排除掉文件夹自身 (WebDAV 通常会把当前请求的文件夹作为第一个结果返回)
// 通过判断 URL 结尾是否一致来简单过滤,或者判断 IsCollection 且 Uri 相同
// 这里简单处理:只要名字不为空
var name = System.Net.WebUtility.UrlDecode(res.Uri.Split('/').LastOrDefault());
if (string.IsNullOrEmpty(name)) continue;
// 如果名字和请求的目录名一样,可能是它自己,跳过 (这需要根据具体服务器响应调整)
// 更稳妥的是比较 Uri
list.Add(new UnifiedFileItem
{
Name = name,
FullPath = res.Uri.ToString(), // WebDAV 需要完整 URI
IsFolder = res.IsCollection,
Size = res.ContentLength ?? 0,
LastModified = res.LastModifiedDate
});
}
}
return list;
}
public async Task<Stream> OpenReadAsync(string fullPath)
{
// WebDAV 获取流
var res = await _client.GetRawFile(fullPath);
if (!res.IsSuccessful) throw new IOException($"WebDAV Error: {res.StatusCode}");
return res.Stream;
}
public async Task DisconnectAsync() => await Task.CompletedTask;
public void Dispose() => _client?.Dispose();
}
}

View File

@@ -0,0 +1,24 @@
using BetterLyrics.WinUI3.Enums;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
namespace BetterLyrics.WinUI3.Models
{
public partial class FolderNode : ObservableObject
{
public FileSourceType SourceType { get; set; } = FileSourceType.Local;
public string FolderName { get; set; } = "";
public string FolderPath { get; set; } = "";
public string MediaFolderId { get; set; } = "";
public ObservableCollection<FolderNode> SubFolders { get; set; } = new();
[ObservableProperty] public partial bool IsExpanded { get; set; }
}
}

View File

@@ -1,5 +1,5 @@
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using CommunityToolkit.Mvvm.DependencyInjection;
using System;
using System.Collections.Generic;
@@ -9,7 +9,7 @@ namespace BetterLyrics.WinUI3.Models
{
public class LyricsData
{
private static readonly IResourceService _resourceService = Ioc.Default.GetRequiredService<IResourceService>();
private static readonly ILocalizationService _localizationService = Ioc.Default.GetRequiredService<ILocalizationService>();
public List<LyricsLine> LyricsLines { get; set; } = [];
public string? LanguageCode
@@ -29,122 +29,15 @@ namespace BetterLyrics.WinUI3.Models
LyricsLines = lyricsLines;
}
public void SetTranslatedText(LyricsData translationData, int toleranceMs = 50)
{
foreach (var line in LyricsLines)
{
// 在翻译歌词中查找与当前行开始时间最接近且在容忍范围内的行
var transLine = translationData.LyricsLines
.FirstOrDefault(t => Math.Abs(t.StartMs - line.StartMs) <= toleranceMs);
if (transLine != null)
{
// 此处 transLine.OriginalText 指翻译中的“原文”属性
line.TranslatedText = transLine.OriginalText;
}
else
{
// 没有匹配的翻译
line.TranslatedText = "";
}
}
}
public void SetPhoneticText(LyricsData phoneticData, int toleranceMs = 50)
{
foreach (var line in LyricsLines)
{
// 在音译歌词中查找与当前行开始时间最接近且在容忍范围内的行
var transLine = phoneticData.LyricsLines
.FirstOrDefault(t => Math.Abs(t.StartMs - line.StartMs) <= toleranceMs);
if (transLine != null)
{
// 此处 transLine.OriginalText 指音译中的“原文”属性
line.PhoneticText = transLine.OriginalText;
}
else
{
// 没有匹配的音译
line.PhoneticText = "";
}
}
}
public void SetTranslation(string translation)
{
List<string> translationArr = translation.Split(StringHelper.NewLine).ToList();
int i = 0;
foreach (var line in LyricsLines)
{
if (i >= translationArr.Count)
{
line.TranslatedText = ""; // No translation available, keep empty
}
else
{
line.TranslatedText = translationArr[i];
}
i++;
}
}
public void SetTransliteration(string transliteration)
{
List<string> transliterationArr = transliteration.Split(StringHelper.NewLine).ToList();
int i = 0;
foreach (var line in LyricsLines)
{
if (i >= transliterationArr.Count)
{
line.PhoneticText = ""; // No transliteration available, keep empty
}
else
{
line.PhoneticText = transliterationArr[i];
}
i++;
}
}
public static LyricsData GetNotfoundPlaceholder()
{
return new LyricsData([new LyricsLine
{
StartMs = 0,
EndMs = (int)TimeSpan.FromMinutes(99).TotalMilliseconds,
OriginalText = _resourceService.GetLocalizedString("LyricsNotFound"),
OriginalText = _localizationService.GetLocalizedString("LyricsNotFound"),
}]);
}
public static LyricsData GetLoadingPlaceholder()
{
return new LyricsData()
{
LyricsLines = [
new LyricsLine
{
StartMs = 0,
EndMs = (int)TimeSpan.FromMinutes(99).TotalMilliseconds,
OriginalText = "● ● ●",
},
],
LanguageCode = "N/A",
};
}
public LyricsLine? GetLyricsLine(double sec)
{
for (int i = 0; i < LyricsLines.Count; i++)
{
var line = LyricsLines[i];
if (line.StartMs > sec * 1000)
{
return LyricsLines.ElementAtOrDefault(i - 1);
}
}
return null;
}
}
}

View File

@@ -1,11 +1,11 @@
// 2025/6/23 by Zhe Fang
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models.FileSystem;
using BetterLyrics.WinUI3.Services.FileSystemService;
using BetterLyrics.WinUI3.Services.FileSystemService.Providers;
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Text.Json.Serialization;
using System.Threading;
namespace BetterLyrics.WinUI3.Models
{
@@ -14,32 +14,84 @@ namespace BetterLyrics.WinUI3.Models
[ObservableProperty] public partial string Id { get; set; } = Guid.NewGuid().ToString();
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool IsEnabled { get; set; } = true;
[ObservableProperty][NotifyPropertyChangedRecipients] public partial bool IsRealTimeWatchEnabled { get; set; } = false;
[ObservableProperty][NotifyPropertyChangedRecipients][NotifyPropertyChangedFor(nameof(ConnectionSummary))] public partial string Path { get; set; }
[ObservableProperty]
[NotifyPropertyChangedRecipients]
[NotifyPropertyChangedFor(nameof(IsLocal))]
[NotifyPropertyChangedFor(nameof(ConnectionSummary))]
[NotifyPropertyChangedFor(nameof(UriString))]
public partial FileSourceType SourceType { get; set; } = FileSourceType.Local;
[ObservableProperty][NotifyPropertyChangedRecipients] public partial string Name { get; set; }
[ObservableProperty] public partial string UserName { get; set; }
// 连接属性
[ObservableProperty][NotifyPropertyChangedFor(nameof(UriString))] public partial string UserName { get; set; }
[ObservableProperty][NotifyPropertyChangedFor(nameof(UriString))] public partial string UriScheme { get; set; }
[ObservableProperty][NotifyPropertyChangedFor(nameof(UriString))] public partial string UriHost { get; set; }
[ObservableProperty][NotifyPropertyChangedFor(nameof(UriString))] public partial int UriPort { get; set; } = -1;
[ObservableProperty] public partial int Port { get; set; } = -1;
[ObservableProperty]
[NotifyPropertyChangedRecipients]
[NotifyPropertyChangedFor(nameof(ConnectionSummary))]
[NotifyPropertyChangedFor(nameof(UriString))]
public partial string UriPath { get; set; }
[JsonIgnore] public string Password { get; set; }
[JsonIgnore] public bool IsLocal => SourceType == FileSourceType.Local;
[JsonIgnore][ObservableProperty] public partial bool IsIndexing { get; set; } = false;
[JsonIgnore][ObservableProperty] public partial double IndexingProgress { get; set; } = 0;
[JsonIgnore][ObservableProperty] public partial string IndexingStatusText { get; set; } = "";
[JsonIgnore][ObservableProperty] public partial bool IsCleaningUp { get; set; } = false;
[JsonIgnore][ObservableProperty] public partial string CleaningUpStatusText { get; set; } = "";
[ObservableProperty][NotifyPropertyChangedRecipients] public partial DateTime? LastSyncTime { get; set; }
[ObservableProperty][NotifyPropertyChangedRecipients] public partial AutoScanInterval ScanInterval { get; set; } = AutoScanInterval.Disabled;
public Uri GetStandardUri()
{
try
{
if (IsLocal)
{
return new Uri(UriPath);
}
var builder = new UriBuilder
{
Scheme = UriScheme ?? "file",
Host = UriHost,
Port = UriPort,
};
if (!string.IsNullOrEmpty(UriPath))
{
string cleanPath = UriPath.Replace("\\", "/");
if (!cleanPath.StartsWith("/")) cleanPath = "/" + cleanPath;
builder.Path = cleanPath;
}
return builder.Uri;
}
catch (Exception)
{
return new Uri("about:blank");
}
}
// 例smb://user@host:445/share/path
[JsonIgnore]
public string UriString => GetStandardUri().AbsoluteUri;
[JsonIgnore]
public string ConnectionSummary
{
get
{
if (IsLocal) return Path;
return $"{SourceType} - {Path} {(string.IsNullOrEmpty(UserName) ? "" : $"({UserName})")}";
if (IsLocal) return UriPath;
return $"{UriScheme}://{UriHost}{(UriPort > 0 ? ":" + UriPort : "")}/{UriPath?.TrimStart('/', '\\')} {(string.IsNullOrEmpty(UserName) ? "" : $"({UserName})")}";
}
}
@@ -49,7 +101,8 @@ namespace BetterLyrics.WinUI3.Models
public MediaFolder(string path)
{
Path = path;
UriPath = path;
SourceType = FileSourceType.Local;
}
public IUnifiedFileSystem? CreateFileSystem()
@@ -62,12 +115,13 @@ namespace BetterLyrics.WinUI3.Models
return SourceType switch
{
FileSourceType.Local => new LocalFileSystem(Path),
FileSourceType.SMB => new SMBFileSystem(Path, UserName, Password),
FileSourceType.FTP => new FTPFileSystem(Path, UserName, Password, Port, Path),
FileSourceType.WebDav => new WebDavFileSystem(Path, UserName, Password, Port, Path),
FileSourceType.Local => new LocalFileSystem(this),
FileSourceType.SMB => new SMBFileSystem(this),
FileSourceType.FTP => new FTPFileSystem(this),
FileSourceType.WebDav => new WebDavFileSystem(this),
_ => throw new NotImplementedException()
};
}
}
}
}

View File

@@ -1,6 +1,4 @@
using ATL;
namespace BetterLyrics.WinUI3.Models
namespace BetterLyrics.WinUI3.Models
{
public class PlayQueueItem
{

View File

@@ -1,9 +1,7 @@
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Helper;
using CommunityToolkit.Mvvm.ComponentModel;
using Microsoft.UI;
using System;
using System.Linq;
using Windows.UI;
namespace BetterLyrics.WinUI3.Models.Settings

View File

@@ -6,37 +6,18 @@ namespace BetterLyrics.WinUI3.Models
{
public partial class SongsTabInfo : BaseViewModel
{
public string Name { get; set; }
public string Name { get; set; } = "";
public string Icon { get; set; }
public string Icon { get; set; } = "";
public bool IsClosable { get; set; }
public CommonSongProperty FilterProperty { get; set; } = CommonSongProperty.Title;
[ObservableProperty]
public partial bool IsStarred { get; set; }
public string FilterValue { get; set; } = "";
public CommonSongProperty FilterProperty { get; set; }
public string FilterValue { get; set; }
public bool IsDefault => Icon == "\uE8A9";
public SongsTabInfo()
{
Name = string.Empty;
Icon = string.Empty;
IsClosable = true;
IsStarred = false;
FilterProperty = CommonSongProperty.Title;
FilterValue = string.Empty;
}
public SongsTabInfo(string name, string icon, bool isClosable, bool isStarred, CommonSongProperty filterProperty, string filterValue)
{
Name = name;
Icon = icon;
IsClosable = isClosable;
IsStarred = isStarred;
FilterProperty = filterProperty;
FilterValue = filterValue;
}
}
}

View File

@@ -1,14 +0,0 @@
namespace BetterLyrics.WinUI3.Models
{
public class TrimmedTrack
{
public string Title { get; set; }
public string Artist { get; set; }
public string Album { get; set; }
public int? Year { get; set; }
public string Genre { get; set; }
public string FilePath { get; set; }
public int Duration { get; set; }
public byte[]? AlbumArt { get; set; }
}
}

View File

@@ -1,8 +1,7 @@
using ATL;
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Helper.BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Services.FileSystemService;
using BetterLyrics.WinUI3.Services.SettingsService;
using Microsoft.Extensions.Logging;
using System;
@@ -24,11 +23,13 @@ namespace BetterLyrics.WinUI3.Services.AlbumArtSearchService
private readonly HttpClient _iTunesHttpClinet;
private readonly ISettingsService _settingsService;
private readonly IFileSystemService _fileSystemService;
private readonly ILogger _logger;
public AlbumArtSearchService(ISettingsService settingsService, ILogger<AlbumArtSearchService> logger)
public AlbumArtSearchService(ISettingsService settingsService, IFileSystemService fileSystemService, ILogger<AlbumArtSearchService> logger)
{
_settingsService = settingsService;
_fileSystemService = fileSystemService;
_logger = logger;
_iTunesHttpClinet = new();
}
@@ -79,70 +80,54 @@ namespace BetterLyrics.WinUI3.Services.AlbumArtSearchService
private async Task<byte[]?> SearchFile(SongInfo songInfo)
{
foreach (var folder in _settingsService.AppSettings.LocalMediaFolders)
var enabledIds = _settingsService.AppSettings.LocalMediaFolders
.Where(f => f.IsEnabled)
.Select(f => f.Id)
.ToList();
if (enabledIds.Count == 0) return null;
var allFiles = await _fileSystemService.GetParsedFilesAsync(enabledIds);
allFiles = allFiles.Where(x => FileHelper.MusicExtensions.Contains(Path.GetExtension(x.FileName))).ToList();
FileCacheEntity? bestMatch = null;
foreach (var item in allFiles)
{
if (!folder.IsEnabled) continue;
var ext = Path.GetExtension(item.FileName).ToLower();
if (!FileHelper.MusicExtensions.Contains(ext)) continue;
try
bool isMetadataMatch = (item.Title == songInfo.Title && item.Artists == songInfo.DisplayArtists);
bool isFilenameMatch = StringHelper.IsSwitchableNormalizedMatch(
Path.GetFileNameWithoutExtension(item.FileName),
songInfo.DisplayArtists,
songInfo.Title
);
if (isMetadataMatch || isFilenameMatch)
{
using var fs = folder.CreateFileSystem();
if (fs == null) continue;
if (!await fs.ConnectAsync()) continue;
// 递归扫描
var foldersToScan = new Queue<string>();
foldersToScan.Enqueue(""); // 根目录
while (foldersToScan.Count > 0)
{
var currentPath = foldersToScan.Dequeue();
var items = await fs.GetFilesAsync(currentPath);
foreach (var item in items)
{
if (item.IsFolder)
{
foldersToScan.Enqueue(Path.Combine(currentPath, item.Name));
continue;
}
var ext = Path.GetExtension(item.Name).ToLower();
if (FileHelper.MusicExtensions.Contains(ext))
{
try
{
using (var stream = await fs.OpenReadAsync(item.FullPath))
{
var track = new ExtendedTrack(item.FullPath, stream);
bool isMetadataMatch = (track.Title == songInfo.Title && track.Artist == songInfo.DisplayArtists);
bool isFilenameMatch = StringHelper.IsSwitchableNormalizedMatch(
Path.GetFileNameWithoutExtension(item.Name),
songInfo.DisplayArtists,
songInfo.Title
);
if (isMetadataMatch || isFilenameMatch)
{
var bytes = track.EmbeddedPictures.FirstOrDefault()?.PictureData;
if (bytes != null && bytes.Length > 0)
{
return bytes;
}
}
}
}
catch
{
}
}
}
}
bestMatch = item;
break;
}
catch
}
if (bestMatch == null || string.IsNullOrEmpty(bestMatch.LocalAlbumArtPath))
{
return null;
}
try
{
if (File.Exists(bestMatch.LocalAlbumArtPath))
{
return await File.ReadAllBytesAsync(bestMatch.LocalAlbumArtPath);
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"读取本地缓存失败: {ex.Message}");
}
return null;
}

View File

@@ -0,0 +1,625 @@
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Services.FileSystemService.Providers;
using BetterLyrics.WinUI3.Services.LocalizationService;
using BetterLyrics.WinUI3.Services.SettingsService;
using BetterLyrics.WinUI3.ViewModels;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkit.Mvvm.Messaging.Messages;
using Microsoft.Extensions.Logging;
using SQLite;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Services.FileSystemService
{
public partial class FileSystemService : BaseViewModel, IFileSystemService,
IRecipient<PropertyChangedMessage<AutoScanInterval>>,
IRecipient<PropertyChangedMessage<bool>>
{
private readonly ISettingsService _settingsService;
private readonly ILocalizationService _localizationService;
private readonly ILogger<FileSystemService> _logger;
private readonly SQLiteAsyncConnection _db;
private bool _isInitialized = false;
// 定时器字典
private readonly ConcurrentDictionary<string, CancellationTokenSource> _folderTimerTokens = new();
// 当前正在执行的扫描任务字典
private readonly ConcurrentDictionary<string, CancellationTokenSource> _activeScanTokens = new();
private static readonly SemaphoreSlim _dbLock = new(1, 1);
private static readonly SemaphoreSlim _folderScanLock = new(1, 1);
public FileSystemService(ISettingsService settingsService, ILocalizationService localizationService, ILogger<FileSystemService> logger)
{
_logger = logger;
_localizationService = localizationService;
_settingsService = settingsService;
_db = new SQLiteAsyncConnection(PathHelper.FilesCachePath);
}
public async Task InitializeAsync()
{
if (_isInitialized) return;
await _db.CreateTableAsync<FileCacheEntity>();
_isInitialized = true;
}
public async Task<List<FileCacheEntity>> GetFilesAsync(IUnifiedFileSystem provider, FileCacheEntity? parentFolder, string configId, bool forceRefresh = false)
{
await InitializeAsync();
string queryParentUri;
if (parentFolder == null)
{
if (!forceRefresh) forceRefresh = true;
queryParentUri = "";
}
else
{
queryParentUri = parentFolder.Uri;
}
List<FileCacheEntity> cachedEntities = new List<FileCacheEntity>();
if (parentFolder != null)
{
cachedEntities = await _db.Table<FileCacheEntity>()
.Where(x => x.MediaFolderId == configId && x.ParentUri == queryParentUri)
.ToListAsync();
}
bool needSync = forceRefresh || cachedEntities.Count == 0;
if (needSync)
{
cachedEntities = await SyncAsync(provider, parentFolder, configId);
}
return cachedEntities;
}
/// <summary>
/// 从远端/本地同步文件至数据库,该阶段不会解析文件全部元数据。
/// <para/>
/// 如果某个已有文件被修改或有新文件被添加,会预留空位,等待后续填充(通常交给 <see cref="ScanMediaFolderAsync"/> 完成)
/// </summary>
/// <param name="provider"></param>
/// <param name="parentFolder"></param>
/// <param name="configId"></param>
/// <returns></returns>
private async Task<List<FileCacheEntity>> SyncAsync(IUnifiedFileSystem provider, FileCacheEntity? parentFolder, string configId)
{
List<FileCacheEntity> remoteItems;
try
{
remoteItems = await provider.GetFilesAsync(parentFolder);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Network sync error: {ex.Message}");
return [];
}
if (remoteItems == null) return [];
string targetParentUri = "";
if (remoteItems.Count > 0)
{
targetParentUri = remoteItems[0].ParentUri ?? "";
}
else if (parentFolder != null)
{
targetParentUri = parentFolder.Uri;
}
else
{
return [];
}
try
{
await _db.RunInTransactionAsync(conn =>
{
var dbItems = conn.Table<FileCacheEntity>()
.Where(x => x.MediaFolderId == configId && x.ParentUri == targetParentUri)
.ToList();
var dbMap = dbItems.ToDictionary(x => x.Uri, x => x);
var remoteMap = remoteItems
.GroupBy(x => x.Uri)
.Select(g => g.First())
.ToDictionary(x => x.Uri, x => x);
var toInsert = new List<FileCacheEntity>();
var toUpdate = new List<FileCacheEntity>();
var toDelete = new List<FileCacheEntity>();
foreach (var remote in remoteItems)
{
if (dbMap.TryGetValue(remote.Uri, out var existing))
{
bool isChanged = existing.FileSize != remote.FileSize ||
existing.LastModified != remote.LastModified;
if (isChanged)
{
existing.FileSize = remote.FileSize;
existing.LastModified = remote.LastModified;
existing.IsMetadataParsed = false; // 标记为未解析,下次会重新读取元数据
toUpdate.Add(existing);
}
else
{
// 数据库里原有的 Title, Artist, LocalAlbumArtPath 都会被完美保留
}
}
else
{
toInsert.Add(remote);
}
}
foreach (var dbItem in dbItems)
{
if (!remoteMap.ContainsKey(dbItem.Uri))
{
toDelete.Add(dbItem);
}
}
if (toInsert.Count > 0) conn.InsertAll(toInsert);
if (toUpdate.Count > 0) conn.UpdateAll(toUpdate);
if (toDelete.Count > 0)
{
foreach (var item in toDelete) conn.Delete(item);
}
});
var finalItems = await _db.Table<FileCacheEntity>()
.Where(x => x.MediaFolderId == configId && x.ParentUri == targetParentUri)
.ToListAsync();
FolderUpdated?.Invoke(this, targetParentUri);
return finalItems;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Database sync error: {ex.Message}");
return [];
}
}
public async Task UpdateMetadataAsync(FileCacheEntity entity)
{
// 现在的实体已经包含了完整信息,直接 Update 即可
// 我们只需要确保 Where 子句用的是主键或者 Uri
// 简化版 SQL直接用 ORM 的 Update
// 但因为 entity 对象可能包含一些不应该被覆盖的旧数据(如果多线程操作),
// 手写 SQL 只更新 Metadata 字段更安全。
string sql = @"
UPDATE FileCache
SET
Title = ?, Artists = ?, Album = ?,
Year = ?, Bitrate = ?, SampleRate = ?, BitDepth = ?,
Duration = ?, AudioFormatName = ?, AudioFormatShortName = ?, Encoder = ?,
EmbeddedLyrics = ?, LocalAlbumArtPath = ?,
IsMetadataParsed = 1
WHERE Id = ?"; // 推荐用 Id (主键) 最快,如果没有 Id 则用 Uri
await _db.ExecuteAsync(sql,
entity.Title, entity.Artists, entity.Album,
entity.Year, entity.Bitrate, entity.SampleRate, entity.BitDepth,
entity.Duration, entity.AudioFormatName, entity.AudioFormatShortName, entity.Encoder,
entity.EmbeddedLyrics, entity.LocalAlbumArtPath,
entity.Id // WHERE Id = ?
);
}
public async Task<Stream?> OpenFileAsync(IUnifiedFileSystem provider, FileCacheEntity entity)
{
// 直接传递实体给 Provider
return await provider.OpenReadAsync(entity);
}
public async Task DeleteCacheForMediaFolderAsync(MediaFolder folder)
{
_dispatcherQueue.TryEnqueue(() =>
{
folder.CleaningUpStatusText = _localizationService.GetLocalizedString("FileSystemServicePrepareToClean");
folder.IsCleaningUp = true;
});
if (_folderTimerTokens.TryRemove(folder.Id, out var timerCts))
{
timerCts.Cancel();
timerCts.Dispose();
_logger.LogInformation("DeleteCacheForMediaFolderAsync: {}", "cts.Dispose();");
}
if (_activeScanTokens.TryGetValue(folder.Id, out var activeScanCts))
{
activeScanCts.Cancel();
// 强制终止正在扫描的操作
}
try
{
await _folderScanLock.WaitAsync();
try
{
_dispatcherQueue.TryEnqueue(() =>
{
folder.CleaningUpStatusText = _localizationService.GetLocalizedString("FileSystemServiceCleaningCache");
});
await InitializeAsync();
await _dbLock.WaitAsync();
try
{
await _db.ExecuteAsync("DELETE FROM FileCache WHERE MediaFolderId = ?", folder.Id);
await _db.ExecuteAsync("VACUUM");
}
finally
{
_dbLock.Release();
}
}
finally
{
_folderScanLock.Release();
}
}
catch (Exception ex)
{
_logger.LogError("DeleteCacheForMediaFolderAsync: {}", ex.Message);
}
finally
{
_dispatcherQueue.TryEnqueue(() =>
{
folder.CleaningUpStatusText = "";
folder.IsCleaningUp = false;
folder.LastSyncTime = null;
});
}
}
public async Task ScanMediaFolderAsync(MediaFolder folder, CancellationToken token = default)
{
if (folder == null || !folder.IsEnabled) return;
using var scanCts = CancellationTokenSource.CreateLinkedTokenSource(token);
_activeScanTokens[folder.Id] = scanCts;
_dispatcherQueue.TryEnqueue(() =>
{
folder.IsIndexing = true;
folder.IndexingProgress = 0;
folder.IndexingStatusText = _localizationService.GetLocalizedString("FileSystemServiceWaitingForScan");
});
try
{
await _folderScanLock.WaitAsync(scanCts.Token);
_dispatcherQueue.TryEnqueue(() => folder.IndexingStatusText = _localizationService.GetLocalizedString("FileSystemServiceConnecting"));
await InitializeAsync();
using var fs = folder.CreateFileSystem();
if (fs == null || !await fs.ConnectAsync())
{
_dispatcherQueue.TryEnqueue(() => folder.IndexingStatusText = _localizationService.GetLocalizedString("FileSystemServiceConnectFailed"));
return;
}
_dispatcherQueue.TryEnqueue(() => folder.IndexingStatusText = _localizationService.GetLocalizedString("FileSystemServiceFetchingFileList"));
var filesToProcess = new List<FileCacheEntity>();
var foldersToScan = new Queue<FileCacheEntity?>();
foldersToScan.Enqueue(null); // 根目录
while (foldersToScan.Count > 0)
{
if (scanCts.Token.IsCancellationRequested) return;
var currentParent = foldersToScan.Dequeue();
var items = await GetFilesAsync(fs, currentParent, folder.Id, forceRefresh: true);
foreach (var item in items)
{
if (item.IsDirectory)
{
foldersToScan.Enqueue(item);
}
else
{
var ext = Path.GetExtension(item.FileName).ToLower();
if (FileHelper.AllSupportedExtensions.Contains(ext))
{
filesToProcess.Add(item);
}
}
}
}
int total = filesToProcess.Count;
int current = 0;
foreach (var item in filesToProcess)
{
if (scanCts.Token.IsCancellationRequested) return;
current++;
if (current % 10 == 0 || current == total)
{
double progress = (double)current / total * 100;
_dispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Low, () =>
{
folder.IndexingProgress = progress;
folder.IndexingStatusText = $"{_localizationService.GetLocalizedString("FileSystemServiceParsing")} {current}/{total}";
});
}
if (item.IsMetadataParsed) continue;
var ext = Path.GetExtension(item.FileName).ToLower();
try
{
if (FileHelper.MusicExtensions.Contains(ext))
{
using var originalStream = await OpenFileAsync(fs, item);
if (originalStream == null) continue;
ExtendedTrack track;
if (originalStream.CanSeek)
{
track = new ExtendedTrack(item, originalStream);
}
else
{
using var memStream = new MemoryStream();
await originalStream.CopyToAsync(memStream, scanCts.Token);
memStream.Position = 0;
track = new ExtendedTrack(item, memStream);
}
if (track.Duration > 0)
{
// 保存封面
string? artPath = await SaveAlbumArtToDiskAsync(track);
// 填充实体
item.Title = track.Title;
item.Artists = track.Artist;
item.Album = track.Album;
item.Year = track.Year;
item.Bitrate = track.Bitrate;
item.SampleRate = track.SampleRate;
item.BitDepth = track.BitDepth;
item.Duration = track.Duration;
item.AudioFormatName = track.AudioFormatName;
item.AudioFormatShortName = track.AudioFormatShortName;
item.Encoder = track.Encoder;
item.EmbeddedLyrics = track.RawLyrics; // 内嵌歌词
item.LocalAlbumArtPath = artPath;
item.IsMetadataParsed = true;
}
}
else if (FileHelper.LyricExtensions.Contains(ext))
{
using var stream = await OpenFileAsync(fs, item);
if (stream != null)
{
using var reader = new StreamReader(stream);
string content = await reader.ReadToEndAsync();
item.EmbeddedLyrics = content;
item.IsMetadataParsed = true;
}
}
if (item.IsMetadataParsed)
{
await _dbLock.WaitAsync(token);
try
{
await UpdateMetadataAsync(item);
}
finally
{
_dbLock.Release();
}
}
}
catch (Exception ex)
{
_logger.LogError("ScanMediaFolderAsync: {}", ex.Message);
}
}
_dispatcherQueue.TryEnqueue(() =>
{
folder.LastSyncTime = DateTime.Now;
});
}
catch (OperationCanceledException)
{
// 正常取消
}
catch (Exception ex)
{
_dispatcherQueue.TryEnqueue(() => folder.IndexingStatusText = ex.Message);
}
finally
{
_folderScanLock.Release();
_activeScanTokens.TryRemove(folder.Id, out _);
_dispatcherQueue.TryEnqueue(() =>
{
folder.IsIndexing = false;
folder.IndexingStatusText = "";
folder.IndexingProgress = 100;
});
}
}
public async Task<List<FileCacheEntity>> GetParsedFilesAsync(IEnumerable<string> enabledConfigIds)
{
await InitializeAsync();
if (enabledConfigIds == null || !enabledConfigIds.Any())
{
return new List<FileCacheEntity>();
}
var idList = enabledConfigIds.ToList();
// SQL 逻辑: SELECT * FROM FileCache WHERE IsMetadataParsed = 1 AND MediaFolderId IN (...)
var results = await _db.Table<FileCacheEntity>()
.Where(x => x.IsMetadataParsed && idList.Contains(x.MediaFolderId))
.ToListAsync();
return results;
}
public void StartAllFolderTimers()
{
foreach (var folder in _settingsService.AppSettings.LocalMediaFolders)
{
if (folder.IsEnabled)
{
UpdateFolderTimer(folder);
}
}
}
private void UpdateFolderTimer(MediaFolder folder)
{
if (_folderTimerTokens.TryRemove(folder.Id, out var oldCts))
{
oldCts.Cancel();
oldCts.Dispose();
}
if (!folder.IsEnabled || folder.ScanInterval == AutoScanInterval.Disabled)
{
return;
}
var newCts = new CancellationTokenSource();
_folderTimerTokens[folder.Id] = newCts;
TimeSpan period = folder.ScanInterval switch
{
AutoScanInterval.Every15Minutes => TimeSpan.FromMinutes(15),
AutoScanInterval.EveryHour => TimeSpan.FromHours(1),
AutoScanInterval.Every6Hours => TimeSpan.FromHours(6),
AutoScanInterval.Daily => TimeSpan.FromDays(1),
_ => TimeSpan.FromHours(1)
};
Task.Run(async () =>
{
try
{
using var timer = new PeriodicTimer(period);
while (await timer.WaitForNextTickAsync(newCts.Token))
{
await ScanMediaFolderAsync(folder, newCts.Token);
}
}
catch (OperationCanceledException)
{
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"文件夹 {folder.Name} 定时扫描出错: {ex.Message}");
}
}, newCts.Token);
}
// 参数为 string parentUri表示哪个文件夹的内容变了
public event EventHandler<string>? FolderUpdated;
private async Task<string?> SaveAlbumArtToDiskAsync(ExtendedTrack track)
{
var picData = track.AlbumArtByteArray;
if (picData == null || picData.Length == 0) return null;
try
{
string hash = ComputeHashForBytes(picData);
string safeName = hash + ".jpg";
string localPath = Path.Combine(PathHelper.LocalAlbumArtCacheDirectory, safeName);
if (File.Exists(localPath)) return localPath;
await File.WriteAllBytesAsync(localPath, picData);
return localPath;
}
catch (Exception)
{
return null;
}
}
private string ComputeHashForBytes(byte[] data)
{
using (var md5 = System.Security.Cryptography.MD5.Create())
{
var hashBytes = md5.ComputeHash(data);
return BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant();
}
}
public void Receive(PropertyChangedMessage<AutoScanInterval> message)
{
if (message.Sender is MediaFolder mediaFolder)
{
if (message.PropertyName == nameof(MediaFolder.ScanInterval))
{
UpdateFolderTimer(mediaFolder);
}
}
}
public void Receive(PropertyChangedMessage<bool> message)
{
if (message.Sender is MediaFolder mediaFolder)
{
if (message.PropertyName == nameof(MediaFolder.IsEnabled))
{
UpdateFolderTimer(mediaFolder);
}
}
}
}
}

View File

@@ -0,0 +1,69 @@
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Services.FileSystemService.Providers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Services.FileSystemService
{
public interface IFileSystemService
{
/// <summary>
/// 初始化(连接)数据库
/// </summary>
/// <returns></returns>
Task InitializeAsync();
/// <summary>
/// 从数据库拉取文件(必要时需要从远端/本地同步至数据库)
/// </summary>
/// <param name="provider"></param>
/// <param name="parentFolder"></param>
/// <param name="configId"></param>
/// <param name="forceRefresh">强制需要从远端/本地同步至数据库</param>
/// <returns></returns>
Task<List<FileCacheEntity>> GetFilesAsync(IUnifiedFileSystem provider, FileCacheEntity? parentFolder, string configId, bool forceRefresh = false);
/// <summary>
/// 打开文件(通过远端/本地流)
/// </summary>
/// <param name="provider"></param>
/// <param name="entity"></param>
/// <returns></returns>
Task<Stream?> OpenFileAsync(IUnifiedFileSystem provider, FileCacheEntity entity);
/// <summary>
/// 更新数据库(单个文件)
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
Task UpdateMetadataAsync(FileCacheEntity entity);
/// <summary>
/// 从数据库删除
/// </summary>
/// <param name="folder"></param>
/// <returns></returns>
Task DeleteCacheForMediaFolderAsync(MediaFolder folder);
/// <summary>
/// 从数据库拉取文件(必要时需要从远端/本地同步至数据库)。对于需要解析的文件,打开流填充元数据并回写至数据库。
/// </summary>
/// <param name="folder"></param>
/// <returns></returns>
Task ScanMediaFolderAsync(MediaFolder folder, CancellationToken token = default);
/// <summary>
/// 从数据库拉取
/// </summary>
/// <param name="enabledConfigIds"></param>
/// <returns></returns>
Task<List<FileCacheEntity>> GetParsedFilesAsync(IEnumerable<string> enabledConfigIds);
void StartAllFolderTimers();
event EventHandler<string> FolderUpdated;
}
}

View File

@@ -0,0 +1,26 @@
using BetterLyrics.WinUI3.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Services.FileSystemService
{
public interface IUnifiedFileSystem : IDisposable
{
Task<bool> ConnectAsync();
/// <summary>
/// 从流拉取
/// </summary>
/// <param name="parentFolder"></param>
/// <returns></returns>
Task<List<FileCacheEntity>> GetFilesAsync(FileCacheEntity? parentFolder = null);
/// <summary>
/// 打开流
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
Task<Stream?> OpenReadAsync(FileCacheEntity file);
Task DisconnectAsync();
}
}

View File

@@ -0,0 +1,177 @@
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using FluentFTP;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net; // 用于 WebUtility.UrlDecode
using System.Text; // ★ 修复 Encoding 报错的关键
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Services.FileSystemService.Providers
{
public partial class FTPFileSystem : IUnifiedFileSystem
{
private readonly AsyncFtpClient _client;
private readonly MediaFolder _config;
public FTPFileSystem(MediaFolder config)
{
_config = config ?? throw new ArgumentNullException(nameof(config));
var ftpConfig = new FtpConfig
{
ConnectTimeout = 5000,
DataConnectionConnectTimeout = 5000,
ReadTimeout = 10000,
// 忽略证书错误
ValidateAnyCertificate = true
};
int port = _config.UriPort > 0 ? _config.UriPort : 0;
_client = new AsyncFtpClient(
_config.UriHost,
_config.UserName ?? "anonymous",
_config.Password ?? "",
port,
ftpConfig
);
}
public async Task<bool> ConnectAsync()
{
try
{
if (_client.IsConnected) return true;
await _client.AutoConnect(); // AutoConnect 会自动尝试 FTP/FTPS
return _client.IsConnected;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"FTP连接失败: {ex.Message}");
return false;
}
}
public async Task<List<FileCacheEntity>> GetFilesAsync(FileCacheEntity? parentFolder = null)
{
var result = new List<FileCacheEntity>();
string targetServerPath;
Uri parentUri;
if (parentFolder == null)
{
var rootUri = _config.GetStandardUri();
targetServerPath = rootUri.AbsolutePath;
parentUri = rootUri;
}
else
{
targetServerPath = GetServerPathFromUri(parentFolder.Uri);
parentUri = new Uri(parentFolder.Uri);
}
targetServerPath = WebUtility.UrlDecode(targetServerPath).Replace("\\", "/");
if (string.IsNullOrEmpty(targetServerPath)) targetServerPath = "/";
try
{
var items = await _client.GetListing(targetServerPath, FtpListOption.Auto);
string baseUriSchema = $"{parentUri.Scheme}://{parentUri.Host}";
if (parentUri.Port > 0) baseUriSchema += $":{parentUri.Port}";
foreach (var item in items)
{
// 跳过 . 和 ..
if (item.Name == "." || item.Name == "..") continue;
// 只处理文件和文件夹
if (item.Type != FtpObjectType.File && item.Type != FtpObjectType.Directory) continue;
// 只处理特定后缀文件
if (item.Type == FtpObjectType.File)
{
string extension = Path.GetExtension(item.Name);
if (string.IsNullOrEmpty(extension) || !FileHelper.AllSupportedExtensions.Contains(extension)) continue;
}
var builder = new UriBuilder(baseUriSchema)
{
Path = item.FullName
};
result.Add(new FileCacheEntity
{
MediaFolderId = _config.Id,
// 如果是根目录扫描ParentUri 用 Config 的;否则用传入文件夹的
ParentUri = parentFolder?.Uri ?? _config.GetStandardUri().AbsoluteUri,
Uri = builder.Uri.AbsoluteUri, // 标准化 URI
FileName = item.Name,
IsDirectory = item.Type == FtpObjectType.Directory,
FileSize = item.Size,
// 防止某些服务器返回 MinValue
LastModified = item.Modified == DateTime.MinValue ? DateTime.Now : item.Modified,
IsMetadataParsed = false
});
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"FTP列表获取失败: {targetServerPath} - {ex.Message}");
}
return result;
}
public async Task<Stream?> OpenReadAsync(FileCacheEntity file)
{
if (file == null) return null;
try
{
// 1. 还原服务器路径
string serverPath = GetServerPathFromUri(file.Uri);
// 2. 解码 (Uri 里的空格是 %20FTP 需要真实空格)
serverPath = WebUtility.UrlDecode(serverPath);
// 3. 返回流
// 注意FluentFTP 的 OpenRead 依赖于连接保持活跃
return await _client.OpenRead(serverPath);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"打开文件流失败: {file.FileName} - {ex.Message}");
return null;
}
}
public async Task DisconnectAsync()
{
if (_client.IsConnected)
{
await _client.Disconnect();
}
}
public void Dispose()
{
_client?.Dispose();
GC.SuppressFinalize(this);
}
// 私有辅助方法
private string GetServerPathFromUri(string uriString)
{
var uri = new Uri(uriString);
return uri.AbsolutePath; // 这里拿到的比如是 "/Music/Song%201.mp3"
}
}
}

View File

@@ -0,0 +1,111 @@
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Services.FileSystemService.Providers
{
public partial class LocalFileSystem : IUnifiedFileSystem
{
private readonly MediaFolder _config;
private readonly string _rootLocalPath;
public LocalFileSystem(MediaFolder config)
{
_config = config ?? throw new ArgumentNullException(nameof(config));
_rootLocalPath = config.UriPath;
}
public Task<bool> ConnectAsync()
{
return Task.FromResult(Directory.Exists(_rootLocalPath));
}
public async Task<List<FileCacheEntity>> GetFilesAsync(FileCacheEntity? parentFolder = null)
{
var result = new List<FileCacheEntity>();
string targetPath;
string parentUriString;
try
{
if (parentFolder == null)
{
targetPath = _rootLocalPath;
parentUriString = _config.GetStandardUri().AbsoluteUri;
}
else
{
var uri = new Uri(parentFolder.Uri);
targetPath = uri.LocalPath;
parentUriString = parentFolder.Uri;
}
if (!Directory.Exists(targetPath)) return result;
var dirInfo = new DirectoryInfo(targetPath);
foreach (var item in dirInfo.EnumerateFileSystemInfos())
{
// 跳过系统/隐藏文件
if ((item.Attributes & FileAttributes.Hidden) != 0 || (item.Attributes & FileAttributes.System) != 0) continue;
bool isDir = (item.Attributes & FileAttributes.Directory) == FileAttributes.Directory;
if (!isDir)
{
// 过滤后缀名
if (string.IsNullOrEmpty(item.Extension) || !FileHelper.AllSupportedExtensions.Contains(item.Extension)) continue;
}
var itemUri = new Uri(item.FullName).AbsoluteUri;
long size = 0;
if (!isDir && item is FileInfo fi)
{
size = fi.Length;
}
result.Add(new FileCacheEntity
{
MediaFolderId = _config.Id, // 关联配置 ID
ParentUri = parentUriString, // 记录父级 URI
Uri = itemUri,
FileName = item.Name,
IsDirectory = isDir,
FileSize = size,
LastModified = item.LastWriteTime
});
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine($"Local scan error: {ex.Message}");
}
return await Task.FromResult(result);
}
public async Task<Stream?> OpenReadAsync(FileCacheEntity entity)
{
if (entity == null) return null;
string localPath = new Uri(entity.Uri).LocalPath;
// 使用 FileShare.Read 允许其他程序同时读取
// 使用 useAsync: true 优化异步读写性能
return new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true);
}
public async Task DisconnectAsync() => await Task.CompletedTask;
public void Dispose() { }
}
}

View File

@@ -0,0 +1,211 @@
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using SMBLibrary;
using SMBLibrary.Client;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Services.FileSystemService.Providers
{
public partial class SMBFileSystem : IUnifiedFileSystem
{
private SMB2Client? _client;
private ISMBFileStore? _fileStore;
// 保存配置对象的引用
private readonly MediaFolder _config;
// 缓存解析出来的 Share 名称,因为 TreeConnect 要用
private string _shareName;
public SMBFileSystem(MediaFolder config)
{
_config = config ?? throw new ArgumentNullException(nameof(config));
// 在构造时就解析好 Share 名称,避免后续重复解析
var uri = _config.GetStandardUri();
// Segments[0] 是 "/", Segments[1] 是 "ShareName/"
if (uri.Segments.Length > 1)
{
_shareName = uri.Segments[1].TrimEnd('/');
}
else
{
// 如果没有 ShareName这在 SMB 中通常是不合法的,但在根目录下可能发生
_shareName = "";
}
}
public async Task<bool> ConnectAsync()
{
try
{
_client = new SMB2Client();
// 连接主机
bool connected = _client.Connect(_config.UriHost, SMBTransportType.DirectTCPTransport);
if (!connected) return false;
// 登录
var status = _client.Login(string.Empty, _config.UserName, _config.Password);
if (status != NTStatus.STATUS_SUCCESS) return false;
// 连接共享目录 (TreeConnect)
// SMBLibrary 必须先连接到 Share后续所有文件操作都是基于这个 Share 的相对路径
if (string.IsNullOrEmpty(_shareName)) return false;
_fileStore = _client.TreeConnect(_shareName, out status);
return status == NTStatus.STATUS_SUCCESS;
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// 获取文件列表
/// </summary>
/// <param name="parentFolder">
/// 传入要列出的文件夹实体。
/// 如果传入 null则默认列出 MediaFolder 配置的根目录。
/// </param>
public async Task<List<FileCacheEntity>> GetFilesAsync(FileCacheEntity? parentFolder = null)
{
var result = new List<FileCacheEntity>();
if (_fileStore == null) return result;
string smbPath = GetPathRelativeToShare(parentFolder);
var statusRet = _fileStore.CreateFile(out object handle, out FileStatus status, smbPath,
AccessMask.GENERIC_READ, SMBLibrary.FileAttributes.Directory, ShareAccess.Read,
CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);
if (statusRet != NTStatus.STATUS_SUCCESS) return result;
string parentUriString = parentFolder?.Uri ?? _config.GetStandardUri().AbsoluteUri;
List<QueryDirectoryFileInformation> fileInfo;
do
{
statusRet = _fileStore.QueryDirectory(out fileInfo, handle, "*", FileInformationClass.FileDirectoryInformation);
// 如果查询失败或者没有更多文件fileInfo 可能是 null直接跳出
if (statusRet != NTStatus.STATUS_SUCCESS && statusRet != NTStatus.STATUS_NO_MORE_FILES)
{
break;
}
// 如果是 NO_MORE_FILES 但 fileInfo 依然有残留数据(极少见),或者是 SUCCESS
if (fileInfo != null)
{
foreach (var item in fileInfo.Cast<FileDirectoryInformation>())
{
if (item.FileName == "." || item.FileName == "..") continue;
// 过滤隐藏文件和系统文件
if ((item.FileAttributes & SMBLibrary.FileAttributes.Hidden) == SMBLibrary.FileAttributes.Hidden ||
(item.FileAttributes & SMBLibrary.FileAttributes.System) == SMBLibrary.FileAttributes.System)
{
continue;
}
bool isDir = (item.FileAttributes & SMBLibrary.FileAttributes.Directory) == SMBLibrary.FileAttributes.Directory;
// 后缀名过滤
if (!isDir)
{
string extension = Path.GetExtension(item.FileName);
if (string.IsNullOrEmpty(extension) || !FileHelper.AllSupportedExtensions.Contains(extension)) continue;
}
if (!parentUriString.EndsWith("/")) parentUriString += "/";
var baseUri = new Uri(parentUriString);
var newUri = new Uri(baseUri, item.FileName);
result.Add(new FileCacheEntity
{
MediaFolderId = _config.Id,
ParentUri = parentFolder?.Uri ?? _config.GetStandardUri().AbsoluteUri,
Uri = newUri.AbsoluteUri,
FileName = item.FileName,
IsDirectory = (item.FileAttributes & SMBLibrary.FileAttributes.Directory) == SMBLibrary.FileAttributes.Directory,
FileSize = item.AllocationSize,
LastModified = item.ChangeTime
});
}
}
if (statusRet == NTStatus.STATUS_NO_MORE_FILES) break;
} while (statusRet == NTStatus.STATUS_SUCCESS);
_fileStore.CloseFile(handle);
return result;
}
/// <summary>
/// 打开文件流
/// </summary>
/// <param name="file">只需要传入文件实体即可</param>
public async Task<Stream?> OpenReadAsync(FileCacheEntity file)
{
if (_fileStore == null || file == null) return null;
string smbPath = GetPathRelativeToShare(file);
var ret = _fileStore.CreateFile(out object handle, out FileStatus status, smbPath,
AccessMask.GENERIC_READ | AccessMask.SYNCHRONIZE, 0, ShareAccess.Read, CreateDisposition.FILE_OPEN, 0, null);
if (ret != NTStatus.STATUS_SUCCESS)
throw new IOException($"SMB Open Error: {ret}");
return new SMBReadOnlyStream(_fileStore, handle);
}
public async Task DisconnectAsync()
{
_client?.Disconnect();
await Task.CompletedTask;
}
public void Dispose()
{
_client?.Disconnect();
}
private string GetPathRelativeToShare(FileCacheEntity? entity)
{
Uri targetUri;
if (entity == null)
{
targetUri = _config.GetStandardUri();
}
else
{
targetUri = new Uri(entity.Uri);
}
string absolutePath = Uri.UnescapeDataString(targetUri.AbsolutePath);
string cleanPath = absolutePath.TrimStart('/');
int slashIndex = cleanPath.IndexOf('/');
if (slashIndex == -1)
{
return string.Empty;
}
string relativePath = cleanPath.Substring(slashIndex + 1);
return relativePath.Replace("/", "\\");
}
}
}

View File

@@ -1,18 +1,19 @@
using SMBLibrary;
using SMBLibrary.Client;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace BetterLyrics.WinUI3.Models.FileSystem
namespace BetterLyrics.WinUI3.Services.FileSystemService.Providers
{
public partial class SMBReadOnlyStream : Stream
{
private readonly ISMBFileStore _store;
private readonly object _handle;
private long _position;
private long _length; // 新增:缓存文件长度
private long _length;
// SMB 协议建议的最大读取块大小 (64KB 是最安全的通用值)
private const int MaxReadChunkSize = 65536;
public SMBReadOnlyStream(ISMBFileStore store, object handle)
{
@@ -27,18 +28,15 @@ namespace BetterLyrics.WinUI3.Models.FileSystem
}
else
{
// 如果获取失败,这是一个严重问题,意味着无法 Seek 到末尾
// 暂时设为 0但后续读取可能会出问题
_length = 0;
_length = 0; // 这是一个风险点,但为了不 crash 先设为 0
System.Diagnostics.Debug.WriteLine($"SMB GetLength Error: {status}");
}
}
public override bool CanRead => true;
public override bool CanSeek => true;
public override bool CanWrite => false;
public override long Length => _length;
public override long Position
{
get => _position;
@@ -47,30 +45,49 @@ namespace BetterLyrics.WinUI3.Models.FileSystem
public override int Read(byte[] buffer, int offset, int count)
{
// 保护:如果位置已经超过文件末尾,直接返回 0 (EOF)
if (_position >= _length) return 0;
// 保护:防止读取越界 (请求读取量不能超过剩余量)
long remaining = _length - _position;
int bytesToRequest = (int)Math.Min(count, remaining);
int totalBytesRead = 0;
int remainingRequest = count;
// 为了安全,保留对 remaining 的检查是必须的
if (bytesToRequest <= 0) return 0;
var status = _store.ReadFile(out byte[] data, _handle, _position, bytesToRequest);
if (status == NTStatus.STATUS_END_OF_FILE) return 0;
if (status != NTStatus.STATUS_SUCCESS)
// 循环读取,直到读完请求的数量,或者文件结束
while (remainingRequest > 0)
{
throw new IOException($"SMB Read failed. Status: {status} (Pos: {_position}, Req: {bytesToRequest})");
// 计算剩余文件长度
long remainingFile = _length - _position;
if (remainingFile <= 0) break; // 已到末尾
// 计算本次 SMB 请求的大小 (取三者最小值请求剩余量、文件剩余量、SMB最大块限制)
int bytesToReadThisChunk = (int)Math.Min(Math.Min(remainingRequest, remainingFile), MaxReadChunkSize);
// 发送 SMB 请求
var status = _store.ReadFile(out byte[] data, _handle, _position, bytesToReadThisChunk);
// 处理结果
if (status == NTStatus.STATUS_END_OF_FILE) break;
if (status != NTStatus.STATUS_SUCCESS)
{
// 遇到错误抛出详细信息
throw new IOException($"SMB Read failed. Status: {status}, Position: {_position}, ChunkReq: {bytesToReadThisChunk}");
}
if (data == null || data.Length == 0) break;
// 复制数据到输出 buffer
Array.Copy(data, 0, buffer, offset + totalBytesRead, data.Length);
// 更新指针和计数器
_position += data.Length;
totalBytesRead += data.Length;
remainingRequest -= data.Length;
// 如果实际读到的比请求的少,通常意味着提前到了 EOF或者网络包较小
// 这里选择继续循环尝试,直到读不够或者明确 EOF
if (data.Length < bytesToReadThisChunk) break;
}
if (data == null || data.Length == 0) return 0;
Array.Copy(data, 0, buffer, offset, data.Length);
_position += data.Length;
return data.Length;
return totalBytesRead;
}
public override long Seek(long offset, SeekOrigin origin)
@@ -90,10 +107,9 @@ namespace BetterLyrics.WinUI3.Models.FileSystem
break;
}
// 允许 Seek 超过 EOF (标准 Stream 行为),但在 Read 时会返回 0
if (newPos < 0)
{
throw new IOException("An attempt was made to move the file pointer before the beginning of the file.");
throw new IOException("Seek before beginning.");
}
_position = newPos;
@@ -113,4 +129,4 @@ namespace BetterLyrics.WinUI3.Models.FileSystem
}
}
}
}
}

View File

@@ -0,0 +1,138 @@
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using WebDav;
namespace BetterLyrics.WinUI3.Services.FileSystemService.Providers
{
public partial class WebDavFileSystem : IUnifiedFileSystem
{
private readonly WebDavClient _client;
private readonly MediaFolder _config;
private readonly Uri _baseAddress;
public WebDavFileSystem(MediaFolder config)
{
_config = config ?? throw new ArgumentNullException(nameof(config));
// 构建 BaseAddress (只包含 http://host:port/)
// MediaFolder.GetStandardUri() 返回的是带路径的完整 URI (http://host:port/path)
// 提取出根用于初始化 WebDavClient
var fullUri = _config.GetStandardUri();
// 提取 "http://host:port"
_baseAddress = new Uri($"{fullUri.Scheme}://{fullUri.Authority}");
_client = new WebDavClient(new WebDavClientParams
{
BaseAddress = _baseAddress,
Credentials = new System.Net.NetworkCredential(_config.UserName, _config.Password)
});
}
public async Task<bool> ConnectAsync()
{
try
{
// 测试连接Propfind 请求配置的根路径
// GetStandardUri 已经包含了用户设置的路径
var result = await _client.Propfind(_config.GetStandardUri().AbsoluteUri);
return result.IsSuccessful;
}
catch
{
return false;
}
}
public async Task<List<FileCacheEntity>> GetFilesAsync(FileCacheEntity? parentFolder = null)
{
var list = new List<FileCacheEntity>();
Uri targetUri;
if (parentFolder == null)
{
targetUri = _config.GetStandardUri();
}
else
{
targetUri = new Uri(parentFolder.Uri);
}
var result = await _client.Propfind(targetUri.AbsoluteUri);
if (result.IsSuccessful)
{
string parentUriString = targetUri.AbsoluteUri;
if (!parentUriString.EndsWith("/")) parentUriString += "/";
string targetPathClean = targetUri.AbsolutePath.TrimEnd('/');
foreach (var res in result.Resources)
{
var itemUri = new Uri(_baseAddress, res.Uri);
// 过滤掉文件夹自身
if (itemUri.AbsolutePath.TrimEnd('/') == targetPathClean) continue;
string? name = res.DisplayName;
if (string.IsNullOrEmpty(name))
{
name = itemUri.AbsolutePath.TrimEnd('/').Split('/').Last();
name = System.Net.WebUtility.UrlDecode(name);
}
if (string.IsNullOrEmpty(name)) continue;
if (name.StartsWith(".")) continue;
bool isDir = res.IsCollection;
if (!isDir)
{
string extension = System.IO.Path.GetExtension(name);
// 如果后缀为空或不在白名单,跳过
if (string.IsNullOrEmpty(extension) || !FileHelper.AllSupportedExtensions.Contains(extension)) continue;
}
list.Add(new FileCacheEntity
{
MediaFolderId = _config.Id,
ParentUri = parentFolder?.Uri ?? _config.GetStandardUri().AbsoluteUri,
Uri = itemUri.AbsoluteUri,
FileName = name,
IsDirectory = res.IsCollection,
FileSize = res.ContentLength ?? 0,
LastModified = res.LastModifiedDate ?? DateTime.MinValue,
});
}
}
return list;
}
public async Task<Stream?> OpenReadAsync(FileCacheEntity entity)
{
if (entity == null) return null;
// WebDAV 获取流,直接使用完整 URI
var res = await _client.GetRawFile(entity.Uri);
if (!res.IsSuccessful)
throw new IOException($"WebDAV Error {res.StatusCode}: {res.Description}");
return res.Stream;
}
public async Task DisconnectAsync() => await Task.CompletedTask;
public void Dispose() => _client?.Dispose();
}
}

View File

@@ -2,7 +2,7 @@
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Hooks;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Services.ResourceService;
using BetterLyrics.WinUI3.Services.LocalizationService;
using BetterLyrics.WinUI3.Services.SettingsService;
using BetterLyrics.WinUI3.Views;
using Hqub.Lastfm;
@@ -16,7 +16,7 @@ namespace BetterLyrics.WinUI3.Services.LastFMService
public partial class LastFMService : ILastFMService
{
private readonly ISettingsService _settingsService;
private readonly IResourceService _resourceService;
private readonly ILocalizationService _localizationService;
private readonly LastfmClient _client;
@@ -27,10 +27,10 @@ namespace BetterLyrics.WinUI3.Services.LastFMService
public bool IsAuthenticated { get; private set; }
public LastFMService(ISettingsService settingsService, IResourceService resourceService)
public LastFMService(ISettingsService settingsService, ILocalizationService localizationService)
{
_localizationService = localizationService;
_settingsService = settingsService;
_resourceService = resourceService;
_client = new LastfmClient(Constants.LastFM.ApiKey, Constants.LastFM.SharedSecret);
_client.Session.SessionKey = PasswordVaultHelper.Get(Constants.App.AppName, Constants.LastFM.SessionKeyCredentialKey) ?? string.Empty;
@@ -68,10 +68,10 @@ namespace BetterLyrics.WinUI3.Services.LastFMService
var dialog = new ContentDialog
{
Title = _resourceService.GetLocalizedString("LastFMRequestAuthTitle") ?? "",
Content = _resourceService.GetLocalizedString("LastFMRequestAuthDesc") ?? "",
PrimaryButtonText = _resourceService.GetLocalizedString("LastFMRequestAuthConfirm") ?? "",
CloseButtonText = _resourceService.GetLocalizedString("Cancel") ?? "",
Title = _localizationService.GetLocalizedString("LastFMRequestAuthTitle") ?? "",
Content = _localizationService.GetLocalizedString("LastFMRequestAuthDesc") ?? "",
PrimaryButtonText = _localizationService.GetLocalizedString("LastFMRequestAuthConfirm") ?? "",
CloseButtonText = _localizationService.GetLocalizedString("Cancel") ?? "",
DefaultButton = ContentDialogButton.Close,
XamlRoot = dialogXamlRoot,
};
@@ -95,10 +95,10 @@ namespace BetterLyrics.WinUI3.Services.LastFMService
var dialog = new ContentDialog
{
Title = _resourceService.GetLocalizedString("LastFMRequestUnAuthTitle") ?? "",
Content = _resourceService.GetLocalizedString("LastFMRequestUnAuthDesc") ?? "",
PrimaryButtonText = _resourceService.GetLocalizedString("LastFMRequestUnAuthConfirm") ?? "",
CloseButtonText = _resourceService.GetLocalizedString("Cancel") ?? "",
Title = _localizationService.GetLocalizedString("LastFMRequestUnAuthTitle") ?? "",
Content = _localizationService.GetLocalizedString("LastFMRequestUnAuthDesc") ?? "",
PrimaryButtonText = _localizationService.GetLocalizedString("LastFMRequestUnAuthConfirm") ?? "",
CloseButtonText = _localizationService.GetLocalizedString("Cancel") ?? "",
DefaultButton = ContentDialogButton.Close,
XamlRoot = dialogXamlRoot,
};

View File

@@ -1,12 +0,0 @@
// 2025/6/23 by Zhe Fang
using BetterLyrics.WinUI3.Events;
using System;
namespace BetterLyrics.WinUI3.Services.LibWatcherService
{
public interface ILibWatcherService
{
event EventHandler<LibChangedEventArgs>? MusicLibraryFilesChanged;
}
}

View File

@@ -1,91 +0,0 @@
// 2025/6/23 by Zhe Fang
using BetterLyrics.WinUI3.Events;
using BetterLyrics.WinUI3.Services.SettingsService;
using BetterLyrics.WinUI3.ViewModels;
using Microsoft.UI.Dispatching;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace BetterLyrics.WinUI3.Services.LibWatcherService
{
public class LibWatcherService : BaseViewModel, IDisposable, ILibWatcherService
{
private readonly ISettingsService _settingsService;
private readonly Dictionary<string, FileSystemWatcher> _watchers = [];
public LibWatcherService(ISettingsService settingsService)
{
_settingsService = settingsService;
_settingsService.AppSettings.LocalMediaFolders.CollectionChanged += LocalMediaFolders_CollectionChanged;
_settingsService.AppSettings.LocalMediaFolders.ItemPropertyChanged += LocalMediaFolders_ItemPropertyChanged;
UpdateWatchers();
}
private void LocalMediaFolders_ItemPropertyChanged(object? sender, Collections.ItemPropertyChangedEventArgs e)
{
UpdateWatchers();
}
private void LocalMediaFolders_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
UpdateWatchers();
}
public event EventHandler<LibChangedEventArgs>? MusicLibraryFilesChanged;
public void Dispose()
{
foreach (var watcher in _watchers.Values)
{
watcher.Dispose();
}
_watchers.Clear();
}
private void UpdateWatchers()
{
var folders = _settingsService.AppSettings.LocalMediaFolders;
// 移除不再监听的
foreach (var key in _watchers.Keys.ToList())
{
if (!folders.Any(x => x.Path == key && x.IsEnabled && x.IsRealTimeWatchEnabled))
{
_watchers[key].Dispose();
_watchers.Remove(key);
}
}
// 添加新的监听
foreach (var folder in folders)
{
if (!_watchers.ContainsKey(folder.Path) && Directory.Exists(folder.Path) && folder.IsEnabled && folder.IsRealTimeWatchEnabled)
{
var watcher = new FileSystemWatcher(folder.Path)
{
IncludeSubdirectories = true,
EnableRaisingEvents = true,
};
watcher.Created += (s, e) => OnChanged(folder.Path, e);
watcher.Changed += (s, e) => OnChanged(folder.Path, e);
watcher.Deleted += (s, e) => OnChanged(folder.Path, e);
watcher.Renamed += (s, e) => OnChanged(folder.Path, e);
_watchers[folder.Path] = watcher;
}
}
}
private void OnChanged(string folder, FileSystemEventArgs e)
{
_dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () =>
{
MusicLibraryFilesChanged?.Invoke(
this,
new LibChangedEventArgs(folder, e.FullPath, e.ChangeType)
);
});
}
}
}

View File

@@ -0,0 +1,7 @@
namespace BetterLyrics.WinUI3.Services.LocalizationService
{
public interface ILocalizationService
{
string GetLocalizedString(string id);
}
}

View File

@@ -1,8 +1,8 @@
using Microsoft.Windows.ApplicationModel.Resources;
namespace BetterLyrics.WinUI3.Services.ResourceService
namespace BetterLyrics.WinUI3.Services.LocalizationService
{
public class ResourceService : IResourceService
public class LocalizationService : ILocalizationService
{
private readonly ResourceLoader _resourceLoader = new();

View File

@@ -1,12 +1,11 @@
// 2025/6/23 by Zhe Fang
using ATL;
using BetterLyrics.WinUI3.Enums;
using BetterLyrics.WinUI3.Extensions;
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Helper.BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Providers;
using BetterLyrics.WinUI3.Services.FileSystemService;
using BetterLyrics.WinUI3.Services.SettingsService;
using Lyricify.Lyrics.Helpers;
using Lyricify.Lyrics.Searchers;
@@ -30,11 +29,13 @@ namespace BetterLyrics.WinUI3.Services.LyricsSearchService
private readonly AppleMusic _appleMusic;
private readonly ISettingsService _settingsService;
private readonly IFileSystemService _fileSystemService;
private readonly ILogger _logger;
public LyricsSearchService(ISettingsService settingsService, ILogger<LyricsSearchService> logger)
public LyricsSearchService(ISettingsService settingsService, IFileSystemService fileSystemService, ILogger<LyricsSearchService> logger)
{
_settingsService = settingsService;
_fileSystemService = fileSystemService;
_logger = logger;
_lrcLibHttpClient = new();
@@ -278,92 +279,50 @@ namespace BetterLyrics.WinUI3.Services.LyricsSearchService
{
int maxScore = 0;
MediaFolder? bestFolder = null;
string? bestFilePath = null;
FileCacheEntity? bestFileEntity = null;
MediaFolder? bestFolderConfig = null;
var lyricsSearchResult = new LyricsSearchResult();
if (format.ToLyricsSearchProvider() is LyricsSearchProvider lyricsSearchProvider)
{
lyricsSearchResult.Provider = lyricsSearchProvider;
}
foreach (var folder in _settingsService.AppSettings.LocalMediaFolders)
string targetExt = format.ToFileExtension();
var enabledFolders = _settingsService.AppSettings.LocalMediaFolders
.Where(f => f.IsEnabled)
.ToList();
var enabledIds = enabledFolders.Select(f => f.Id).ToList();
if (enabledIds.Count == 0) return lyricsSearchResult;
var allFiles = await _fileSystemService.GetParsedFilesAsync(enabledIds);
allFiles = allFiles.Where(x => FileHelper.LyricExtensions.Contains(Path.GetExtension(x.FileName))).ToList();
foreach (var item in allFiles)
{
if (!folder.IsEnabled) continue;
try
if (item.FileName.EndsWith(targetExt, StringComparison.OrdinalIgnoreCase))
{
using var fs = folder.CreateFileSystem();
if (fs == null) continue;
if (!await fs.ConnectAsync()) continue;
int score = MetadataComparer.CalculateScore(songInfo, new LyricsSearchResult { Reference = item.FileName });
// 递归扫描
var foldersToScan = new Queue<string>();
foldersToScan.Enqueue(""); // 从根目录开始
string targetExt = format.ToFileExtension();
while (foldersToScan.Count > 0)
if (score > maxScore)
{
var currentPath = foldersToScan.Dequeue();
var items = await fs.GetFilesAsync(currentPath);
maxScore = score;
bestFileEntity = item;
foreach (var item in items)
{
if (item.IsFolder)
{
foldersToScan.Enqueue(Path.Combine(currentPath, item.Name));
continue;
}
if (item.Name.EndsWith(targetExt, StringComparison.OrdinalIgnoreCase))
{
int score = MetadataComparer.CalculateScore(songInfo, new LyricsSearchResult { Reference = item.FullPath });
if (score > maxScore)
{
maxScore = score;
bestFilePath = item.FullPath;
bestFolder = folder;
}
}
}
bestFolderConfig = enabledFolders.FirstOrDefault(f => f.Id == item.MediaFolderId);
}
}
catch (Exception ex)
{
// 日志记录...
}
}
// 4. 如果找到了最佳匹配,读取内容
if (bestFolder != null && bestFilePath != null)
if (bestFileEntity != null)
{
try
{
// 重新连接以读取文件 (因为之前的 fs 已经在 using 结束时释放)
using var fs = bestFolder.CreateFileSystem();
if (fs != null && await fs.ConnectAsync())
{
using var stream = await fs.OpenReadAsync(bestFilePath);
lyricsSearchResult.Raw = bestFileEntity.EmbeddedLyrics;
// 使用 StreamReader 读取文本
// 注意:这里简单使用 Default 编码,如果需要探测编码(FileHelper.GetEncoding)
// 可能需要先读一部分字节来判断,或者使用带编码探测的库。
using var reader = new StreamReader(stream);
string raw = await reader.ReadToEndAsync();
lyricsSearchResult.Reference = bestFilePath;
lyricsSearchResult.MatchPercentage = maxScore;
lyricsSearchResult.Raw = raw;
}
}
catch (Exception)
{
// 读取失败处理
}
lyricsSearchResult.Reference = bestFileEntity.Uri;
lyricsSearchResult.MatchPercentage = maxScore;
}
return lyricsSearchResult;
@@ -371,107 +330,53 @@ namespace BetterLyrics.WinUI3.Services.LyricsSearchService
private async Task<LyricsSearchResult> SearchEmbedded(SongInfo songInfo)
{
int bestScore = 0;
string? bestFilePath = null;
string? bestRaw = null;
// 用于最后回填 Metadata
string? bestTitle = null;
string[]? bestArtists = null;
string? bestAlbum = null;
double bestDuration = 0;
var lyricsSearchResult = new LyricsSearchResult
{
Provider = LyricsSearchProvider.LocalMusicFile,
};
foreach (var folder in _settingsService.AppSettings.LocalMediaFolders)
var enabledIds = _settingsService.AppSettings.LocalMediaFolders
.Where(f => f.IsEnabled)
.Select(f => f.Id)
.ToList();
if (enabledIds.Count == 0) return lyricsSearchResult;
var allFiles = await _fileSystemService.GetParsedFilesAsync(enabledIds);
allFiles = allFiles.Where(x => FileHelper.MusicExtensions.Contains(Path.GetExtension(x.FileName))).ToList();
FileCacheEntity? bestFile = null;
int maxScore = 0;
foreach (var item in allFiles)
{
if (!folder.IsEnabled) continue;
if (string.IsNullOrEmpty(item.EmbeddedLyrics)) continue;
try
int score = MetadataComparer.CalculateScore(songInfo, new LyricsSearchResult
{
using var fs = folder.CreateFileSystem();
if (fs == null) continue;
if (!await fs.ConnectAsync()) continue;
Title = item.Title,
Artists = item.Artists?.Split(ATL.Settings.DisplayValueSeparator),
Album = item.Album,
Duration = item.Duration
});
var foldersToScan = new Queue<string>();
foldersToScan.Enqueue("");
while (foldersToScan.Count > 0)
{
var currentPath = foldersToScan.Dequeue();
var items = await fs.GetFilesAsync(currentPath);
foreach (var item in items)
{
if (item.IsFolder)
{
foldersToScan.Enqueue(Path.Combine(currentPath, item.Name));
continue;
}
var ext = Path.GetExtension(item.Name).ToLower();
if (FileHelper.MusicExtensions.Contains(ext))
{
try
{
using var stream = await fs.OpenReadAsync(item.FullPath);
var track = new ExtendedTrack(item.FullPath, stream);
var raw = track.RawLyrics;
if (!string.IsNullOrEmpty(raw))
{
int score = MetadataComparer.CalculateScore(songInfo, new LyricsSearchResult
{
Title = track.Title,
Artists = track.Artist?.Split(ATL.Settings.DisplayValueSeparator),
Album = track.Album,
Duration = track.Duration,
Reference = item.FullPath,
});
if (score > bestScore)
{
bestScore = score;
bestFilePath = item.FullPath;
bestRaw = raw;
// 缓存当前最佳的元数据,避免最后还需要重新打开文件读一次
bestTitle = track.Title;
bestArtists = track.Artist?.Split(ATL.Settings.DisplayValueSeparator);
bestAlbum = track.Album;
bestDuration = track.Duration;
}
}
}
catch
{
// 单个文件解析失败忽略
}
}
}
}
}
catch
if (score > maxScore)
{
// 文件夹扫描失败忽略
maxScore = score;
bestFile = item;
}
}
if (bestFilePath != null)
if (bestFile != null && maxScore > 0)
{
// 直接使用缓存的数据,不需要 new Track(bestFile) 了
lyricsSearchResult.Title = bestTitle;
lyricsSearchResult.Artists = bestArtists;
lyricsSearchResult.Album = bestAlbum;
lyricsSearchResult.Duration = bestDuration;
lyricsSearchResult.Title = bestFile.Title;
lyricsSearchResult.Artists = bestFile.Artists?.Split(ATL.Settings.DisplayValueSeparator);
lyricsSearchResult.Album = bestFile.Album;
lyricsSearchResult.Duration = bestFile.Duration;
lyricsSearchResult.Raw = bestRaw;
lyricsSearchResult.Reference = bestFilePath;
lyricsSearchResult.MatchPercentage = bestScore;
lyricsSearchResult.Raw = bestFile.EmbeddedLyrics;
lyricsSearchResult.Reference = bestFile.Uri;
lyricsSearchResult.MatchPercentage = maxScore;
}
return lyricsSearchResult;

View File

@@ -9,6 +9,7 @@ using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media.Imaging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

View File

@@ -11,7 +11,6 @@ using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Models.Settings;
using BetterLyrics.WinUI3.Services.AlbumArtSearchService;
using BetterLyrics.WinUI3.Services.DiscordService;
using BetterLyrics.WinUI3.Services.LibWatcherService;
using BetterLyrics.WinUI3.Services.LyricsSearchService;
using BetterLyrics.WinUI3.Services.SettingsService;
using BetterLyrics.WinUI3.Services.TranslationService;
@@ -27,6 +26,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text.Json;
@@ -41,7 +41,8 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
public partial class MediaSessionsService : BaseViewModel, IMediaSessionsService,
IRecipient<PropertyChangedMessage<bool>>,
IRecipient<PropertyChangedMessage<string>>,
IRecipient<PropertyChangedMessage<ChineseRomanization>>
IRecipient<PropertyChangedMessage<ChineseRomanization>>,
IRecipient<PropertyChangedMessage<DateTime?>>
{
private EventSourceReader? _sse = null;
private readonly MediaManager _mediaManager = new();
@@ -52,7 +53,6 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
private readonly ITranslationService _translationService;
private readonly ITransliterationService _transliterationService;
private readonly ISettingsService _settingsService;
private readonly ILibWatcherService _libWatcherService;
private readonly IDiscordService _discordService;
private readonly ILogger<MediaSessionsService> _logger;
@@ -71,7 +71,6 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
ISettingsService settingsService,
IAlbumArtSearchService albumArtSearchService,
ILyricsSearchService lyricsSearchService,
ILibWatcherService libWatcherService,
IDiscordService discordService,
ITranslationService libreTranslateService,
ITransliterationService transliterationService,
@@ -80,7 +79,6 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
_settingsService = settingsService;
_albumArtSearchService = albumArtSearchService;
_lyrcsSearchService = lyricsSearchService;
_libWatcherService = libWatcherService;
_translationService = libreTranslateService;
_transliterationService = transliterationService;
_discordService = discordService;
@@ -91,13 +89,10 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
_settingsService.AppSettings.MediaSourceProvidersInfo.ItemPropertyChanged += MediaSourceProvidersInfo_ItemPropertyChanged;
_settingsService.AppSettings.LocalMediaFolders.CollectionChanged += LocalMediaFolders_CollectionChanged;
_settingsService.AppSettings.LocalMediaFolders.ItemPropertyChanged += LocalMediaFolders_ItemPropertyChanged;
_settingsService.AppSettings.MappedSongSearchQueries.CollectionChanged += MappedSongSearchQueries_CollectionChanged;
_settingsService.AppSettings.MappedSongSearchQueries.ItemPropertyChanged += MappedSongSearchQueries_ItemPropertyChanged;
_libWatcherService.MusicLibraryFilesChanged += LibWatcherService_MusicLibraryFilesChanged;
InitMediaManager();
}
@@ -111,12 +106,6 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
UpdateLyrics();
}
private void LocalMediaFolders_ItemPropertyChanged(object? sender, ItemPropertyChangedEventArgs e)
{
UpdateAlbumArt();
UpdateLyrics();
}
private void LocalMediaFolders_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
UpdateAlbumArt();
@@ -144,12 +133,6 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
}
}
private void LibWatcherService_MusicLibraryFilesChanged(object? sender, LibChangedEventArgs e)
{
UpdateAlbumArt();
UpdateLyrics();
}
private MediaSourceProviderInfo? GetCurrentMediaSourceProviderInfo()
{
var desiredSession = GetCurrentSession();
@@ -693,6 +676,14 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
MediaManager_OnFocusedSessionChanged(null);
}
}
else if (message.Sender is MediaFolder)
{
if (message.PropertyName == nameof(MediaFolder.IsEnabled))
{
UpdateAlbumArt();
UpdateLyrics();
}
}
}
public void Receive(PropertyChangedMessage<string> message)
@@ -726,5 +717,16 @@ namespace BetterLyrics.WinUI3.Services.MediaSessionsService
}
}
public void Receive(PropertyChangedMessage<DateTime?> message)
{
if (message.Sender is MediaFolder)
{
if (message.PropertyName == nameof(MediaFolder.LastSyncTime))
{
UpdateAlbumArt();
UpdateLyrics();
}
}
}
}
}

View File

@@ -1,7 +0,0 @@
namespace BetterLyrics.WinUI3.Services.ResourceService
{
public interface IResourceService
{
string GetLocalizedString(string id);
}
}

View File

@@ -7,7 +7,6 @@ namespace BetterLyrics.WinUI3.Services.SettingsService
public interface ISettingsService
{
AppSettings AppSettings { get; set; }
// App behavior
bool ImportSettings(string importPath);
void ExportSettings(string exportPath);

View File

@@ -7,12 +7,15 @@ using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Models.Settings;
using BetterLyrics.WinUI3.Serialization;
using BetterLyrics.WinUI3.Services.LocalizationService;
using BetterLyrics.WinUI3.ViewModels;
using CommunityToolkit.WinUI;
using Microsoft.UI.Dispatching;
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using Windows.ApplicationModel.Resources;
using Windows.Globalization;
namespace BetterLyrics.WinUI3.Services.SettingsService
@@ -21,11 +24,13 @@ namespace BetterLyrics.WinUI3.Services.SettingsService
public partial class SettingsService : BaseViewModel, ISettingsService
{
private readonly DispatcherQueueTimer _writeAppSettingsTimer;
private readonly ILocalizationService _localizationService;
public AppSettings AppSettings { get; set; }
public SettingsService()
public SettingsService(ILocalizationService localizationService)
{
_localizationService = localizationService;
_writeAppSettingsTimer = _dispatcherQueue.CreateTimer();
AppSettings = ReadAppSettings();
@@ -57,6 +62,7 @@ namespace BetterLyrics.WinUI3.Services.SettingsService
AppSettings.Version = MetadataHelper.AppVersion;
EnsureMediaSourceProvidersInfo();
EnsureStarredPlaylists();
}
private void EnsureMediaSourceProvidersInfo()
@@ -99,6 +105,20 @@ namespace BetterLyrics.WinUI3.Services.SettingsService
}
}
private void EnsureStarredPlaylists()
{
if (!AppSettings.StarredPlaylists.Any(x => x.IsDefault))
{
AppSettings.StarredPlaylists.Insert(0, new SongsTabInfo
{
Name = _localizationService.GetLocalizedString("MusicGalleryPageAllSongs"),
Icon = "\uE8A9",
FilterProperty = CommonSongProperty.Title,
FilterValue = string.Empty
});
}
}
private void AppSettings_ItemPropertyChanged(object? sender, ItemPropertyChangedEventArgs e)
{
WriteAppSettings();

View File

@@ -1,6 +1,4 @@
using BetterLyrics.WinUI3.Models;
using System.Collections.Generic;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Services.TranslationService

View File

@@ -1,10 +1,8 @@
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Serialization;
using BetterLyrics.WinUI3.Services.SettingsService;
using BetterLyrics.WinUI3.ViewModels;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
namespace BetterLyrics.WinUI3.Services.TransliterationService

View File

@@ -1,15 +1,11 @@
using BetterLyrics.WinUI3.Helper;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Models;
using BetterLyrics.WinUI3.Serialization;
using BetterLyrics.WinUI3.Services.SettingsService;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Vanara.PInvoke;
namespace BetterLyrics.WinUI3.Services.TransliterationService
{

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More