Skip to content

Commit e27cdce

Browse files
feat: create default empty mod blacklist profile if none exist
1 parent 0ffafe1 commit e27cdce

File tree

3 files changed

+73
-41
lines changed

3 files changed

+73
-41
lines changed

resources/dist.rc

-393 KB
Binary file not shown.

src/blacklist.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,23 @@ pub fn get_mod_blacklist_profiles(game_path: &String) -> Vec<ModBlacklistProfile
120120
profiles.push(profile);
121121
}
122122
}
123+
124+
// If no profiles exist, create a default empty profile
125+
if profiles.is_empty() {
126+
let profile = ModBlacklistProfile {
127+
name: "Default".to_string(),
128+
mods: vec![],
129+
};
130+
let blacklist_path = Path::new(game_path).join("celemod_blacklist_profiles");
131+
fs::create_dir_all(&blacklist_path).unwrap();
132+
fs::write(
133+
blacklist_path.join("Default.json"),
134+
serde_json::to_string_pretty(&profile).unwrap(),
135+
)
136+
.unwrap();
137+
profiles.push(profile);
138+
}
139+
123140
profiles
124141
}
125142

src/celemod-ui/src/routes/Manage.tsx

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { Icon } from '../components/Icon';
1717
import { Button } from '../components/Button';
1818
import { GlobalContext, useGlobalContext } from '../App';
1919
import { enforceEverest } from '../components/EnforceEverestPage';
20+
import { createPopup, PopupContext } from '../components/Popup';
2021

2122
type DepState = 'resolved' | 'missing' | 'not-enabled' | 'mismatched-version';
2223

@@ -753,59 +754,73 @@ export const Manage = () => {
753754
enabled: boolean,
754755
recursive = true
755756
) => {
756-
if (currentProfile) {
757-
const switchList: string[] = [];
758-
const excludeFromAutoEnableList = [
759-
'CelesteNet.Client',
760-
'Miao.CelesteNet.Client',
761-
];
762-
763-
const addToSwitchList = (name: string) => {
764-
const mod = installedModMap.get(name);
765-
if (mod) {
766-
mod.enabled = enabled;
767-
switchList.push(name);
768-
}
757+
if (!currentProfile) {
758+
createPopup(() => {
759+
const { hide } = useContext(PopupContext);
760+
return (
761+
<div className="popup-content">
762+
<div className="title">{_i18n.t('未选择 Profile')}</div>
763+
<div className="content">{_i18n.t('请先选择一个 Profile 后再启用/禁用 Mod')}</div>
764+
<div className="buttons">
765+
<button onClick={hide}>{_i18n.t('确定')}</button>
766+
</div>
767+
</div>
768+
);
769+
});
770+
return;
771+
}
769772

770-
if (recursive) {
771-
if (enabled) {
772-
const deps = mod?.dependencies
773-
.filter((v) => checkOptionalDep || !v.optional)
773+
const switchList: string[] = [];
774+
const excludeFromAutoEnableList = [
775+
'CelesteNet.Client',
776+
'Miao.CelesteNet.Client',
777+
];
778+
779+
const addToSwitchList = (name: string) => {
780+
const mod = installedModMap.get(name);
781+
if (mod) {
782+
mod.enabled = enabled;
783+
switchList.push(name);
784+
}
774785

775-
// console.log('also enable', deps?.map(v => v.name).join(','), 'for', name);
786+
if (recursive) {
787+
if (enabled) {
788+
const deps = mod?.dependencies
789+
.filter((v) => checkOptionalDep || !v.optional)
776790

777-
for (const dep of deps ?? []) {
778-
if (!('_missing' in dep)) {
779-
if (excludeFromAutoEnableList.includes(dep.name)) continue;
780-
addToSwitchList(dep.name);
781-
}
782-
}
783-
} else {
784-
const orphanDeps = mod?.dependencies.filter(
785-
(v) =>
786-
!('_missing' in v) &&
787-
!v.dependedBy.some((v) => v.enabled && v.name !== name)
788-
).filter((v) =>
789-
checkOptionalDep || !v.optional
790-
)
791+
// console.log('also enable', deps?.map(v => v.name).join(','), 'for', name);
791792

792-
for (const dep of orphanDeps ?? []) {
793+
for (const dep of deps ?? []) {
794+
if (!('_missing' in dep)) {
795+
if (excludeFromAutoEnableList.includes(dep.name)) continue;
793796
addToSwitchList(dep.name);
794797
}
795798
}
799+
} else {
800+
const orphanDeps = mod?.dependencies.filter(
801+
(v) =>
802+
!('_missing' in v) &&
803+
!v.dependedBy.some((v) => v.enabled && v.name !== name)
804+
).filter((v) =>
805+
checkOptionalDep || !v.optional
806+
)
807+
808+
for (const dep of orphanDeps ?? []) {
809+
addToSwitchList(dep.name);
810+
}
796811
}
797-
};
798-
799-
if (typeof names === 'string') {
800-
names = [names];
801-
}
802-
for (const name of names) {
803-
addToSwitchList(name);
804812
}
813+
};
805814

806-
manageCtx.batchSwitchMod(switchList, enabled);
815+
if (typeof names === 'string') {
816+
names = [names];
817+
}
818+
for (const name of names) {
819+
addToSwitchList(name);
807820
}
808821

822+
manageCtx.batchSwitchMod(switchList, enabled);
823+
809824
setHasUnsavedChanges(true);
810825
},
811826
switchProfile: (name: string) => {

0 commit comments

Comments
 (0)