Merge branch 'master' of https://github.com/Zagrios/bs-manager into Zagrios-master

This commit is contained in:
emesan
2023-11-30 21:30:57 +09:00
23 changed files with 1596 additions and 236 deletions
+19 -9
View File
@@ -1,4 +1,4 @@
import { CopyOptions, copy, createReadStream, ensureDir, move, stat, symlink } from "fs-extra";
import { CopyOptions, copy, createReadStream, ensureDir, move, realpath, stat, symlink } from "fs-extra";
import { access, mkdir, rm, readdir, unlink, lstat, readlink } from "fs/promises";
import path from "path";
import { Observable, concatMap, from } from "rxjs";
@@ -165,16 +165,20 @@ export function hashFile(filePath: string, algorithm = "sha256"): Promise<string
}
export async function dirSize(dirPath: string): Promise<number>{
const files = await readdir(dirPath, { withFileTypes: true });
const paths = files.map(async file => {
const fullPath = path.join(dirPath, file.name);
const entries = await readdir(dirPath);
if (file.isDirectory()) return dirSize(fullPath);
const paths = entries.map(async entry => {
const fullPath = path.join(dirPath, entry);
const realPath = await realpath(fullPath);
const stat = await lstat(realPath);
if (file.isFile()) {
const { size } = await stat( fullPath );
return size;
if (stat.isDirectory()) {
return dirSize(fullPath);
}
if (stat.isFile()) {
return stat.size;
}
return 0;
@@ -185,9 +189,15 @@ export async function dirSize(dirPath: string): Promise<number>{
export function rxCopy(src: string, dest: string, option?: CopyOptions): Observable<Progression> {
return from(dirSize(src)).pipe(
const dirSizePromise = dirSize(src).catch(err => {
log.error("dirSizePromise", err);
return 0;
});
return from(dirSizePromise).pipe(
concatMap(totalSize => {
const progress: Progression = { current: 0, total: totalSize };
return new Observable<Progression>(sub => {
sub.next(progress);
copy(src, dest, {...option, filter: (src) => {
@@ -84,7 +84,7 @@ export function FilterPanel({ className, ref, playlist = false, filter, onChange
};
const renderLabel = (text: string | number, isMax: boolean): JSX.Element => {
return <span className={`bg-inherit absolute top-[calc(100%+4px)] h-5 font-bold rounded-md shadow-center shadow-black px-1 flex items-center ${isMax ? "text-lg" : "text-sm"}`}>{text}</span>;
return <span className={`bg-inherit absolute top-[calc(100%+4px)] whitespace-nowrap h-5 font-bold rounded-md shadow-center shadow-black px-1 flex items-center ${isMax ? "text-lg" : "text-sm"}`}>{text}</span>;
};
const onNpssChange = ([min, max]: number[]) => {
@@ -153,7 +153,7 @@ export function MapsPlaylistsPanel({ version, isActive }: Props) {
<div className="h-full rounded-full bg-light-main-color-2 dark:bg-main-color-2 grow p-[6px]">
<input type="text" className="h-full w-full bg-light-main-color-1 dark:bg-main-color-1 rounded-full px-2" placeholder={t("pages.version-viewer.maps.search-bar.search-placeholder")} value={tabIndex === 0 ? mapSearch : playlistSearch} onChange={e => handleSearch(e.target.value)} tabIndex={-1} />
</div>
<BsmDropdownButton className="h-full relative z-[1] flex justify-center" buttonClassName="flex items-center justify-center h-full rounded-full px-2 py-1" icon="filter" text="pages.version-viewer.maps.search-bar.filters-btn" withBar={false}>
<BsmDropdownButton className="h-full relative z-[1] flex justify-center" buttonClassName="flex items-center justify-center h-full rounded-full px-2 py-1" icon="filter" text="pages.version-viewer.maps.search-bar.filters-btn" textClassName="whitespace-nowrap" withBar={false}>
<FilterPanel className="absolute top-[calc(100%+3px)] origin-top w-[500px] h-fit p-2 rounded-md shadow-md shadow-black" filter={mapFilter} onChange={setMapFilter} />
</BsmDropdownButton>
<BsmDropdownButton className="h-full flex aspect-square relative rounded-full z-[1] bg-light-main-color-1 dark:bg-main-color-3" buttonClassName="rounded-full h-full w-full p-[6px]" icon="three-dots" withBar={false} items={dropDownItems} menuTranslationY="6px" align="center" />
@@ -21,9 +21,10 @@ type Props = {
menuTranslationY?: string | number;
children?: JSX.Element;
text?: string;
textClassName?: string;
};
export const BsmDropdownButton = forwardRef(({ className, items, align, withBar = true, icon = "settings", buttonClassName, menuTranslationY, children, text }: Props, fowardRed) => {
export const BsmDropdownButton = forwardRef(({ className, items, align, withBar = true, icon = "settings", buttonClassName, menuTranslationY, children, text, textClassName }: Props, fowardRed) => {
const [expanded, setExpanded] = useState(false);
const t = useTranslation();
const ref = useRef(fowardRed);
@@ -63,7 +64,7 @@ export const BsmDropdownButton = forwardRef(({ className, items, align, withBar
return (
<div ref={ref as unknown as React.LegacyRef<HTMLDivElement>} className={className}>
<BsmButton onClick={() => setExpanded(!expanded)} className={buttonClassName ?? defaultButtonClassName} icon={icon} active={expanded} onClickOutside={handleClickOutside} withBar={withBar} text={text} />
<BsmButton onClick={() => setExpanded(!expanded)} className={buttonClassName ?? defaultButtonClassName} icon={icon} active={expanded} textClassName={textClassName} onClickOutside={handleClickOutside} withBar={withBar} text={text} />
<div className={`py-1 w-fit absolute cursor-pointer top-[calc(100%-4px)] rounded-md bg-inherit text-sm text-gray-800 dark:text-gray-200 shadow-md shadow-black transition-[scale] ease-in-out ${alignClass}`} style={{ scale: expanded ? "1" : "0", translate: `0 ${menuTranslationY}` }}>
{items?.map(
i =>
@@ -53,6 +53,7 @@ import { VolumeOffIcon } from "./icons/volume-off-icon.component";
import { VolumeDownIcon } from "./icons/volume-down-icon.component";
import { GermanIcon } from "./flags/german-icon.component";
import { RussianIcon } from "./flags/russian-icon.component";
import { ChineseIcon } from "./flags/chinese-icon.component";
import { JapanIcon } from "./flags/japan-icon.component";
import { MSModelType } from "shared/models/models/model-saber.model";
import { ModelTypeAvatarIcon } from "./icons/model-type-avatar-icon.component";
@@ -64,7 +65,7 @@ import { EyeCrossIcon } from "./icons/eye-cross-icon.component";
import { ShortcutIcon } from "./icons/shortcut-icon.component";
import { BackupRestoreIcon } from "./icons/backup-restore-icon.component";
export type BsmIconType = BsvMapCharacteristic | MSModelType | ("settings" | "trash" | "favorite" | "folder" | "bsNote" | "check" | "three-dots" | "twitch" | "eye" | "play" | "checkCircleIcon" | "discord" | "info" | "eye-cross" | "terminal" | "desktop" | "oculus" | "add" | "cross" | "task" | "github" | "close" | "thumbUpFill" | "timerFill" | "pause" | "twitter" | "sync" | "chevron-top" | "copy" | "steam" | "edit" | "export" | "patreon" | "search" | "bsMapDifficulty" | "link" | "unlink" | "download" | "filter" | "mee6" | "volume-up" | "volume-off" | "volume-down" | "shortcut" | "backup-restore" | "fr-FR-flag" | "es-ES-flag" | "en-US-flag" | "en-EN-flag" | "de-DE-flag" | "ru-RU-flag" | "ja-JP-flag");
export type BsmIconType = BsvMapCharacteristic | MSModelType | ("settings" | "trash" | "favorite" | "folder" | "bsNote" | "check" | "three-dots" | "twitch" | "eye" | "play" | "checkCircleIcon" | "discord" | "info" | "eye-cross" | "terminal" | "desktop" | "oculus" | "add" | "cross" | "task" | "github" | "close" | "thumbUpFill" | "timerFill" | "pause" | "twitter" | "sync" | "chevron-top" | "copy" | "steam" | "edit" | "export" | "patreon" | "search" | "bsMapDifficulty" | "link" | "unlink" | "download" | "filter" | "mee6" | "volume-up" | "volume-off" | "volume-down" | "shortcut" | "backup-restore" | "fr-FR-flag" | "es-ES-flag" | "en-US-flag" | "en-EN-flag" | "de-DE-flag" | "ru-RU-flag" | "zh-CN-flag" | "ja-JP-flag");
export const BsmIcon = memo(({ className, icon, style }: { className?: string; icon: BsmIconType; style?: CSSProperties }) => {
// TODO : Very ugly very messy, need to find a better way to do this
@@ -118,6 +119,9 @@ export const BsmIcon = memo(({ className, icon, style }: { className?: string; i
if (icon === "ru-RU-flag") {
return <RussianIcon className={className} style={style} />;
}
if (icon === "zh-CN-flag") {
return <ChineseIcon className={className} style={style} />;
}
if (icon === "ja-JP-flag") {
return <JapanIcon className={className} style={style} />;
}
@@ -0,0 +1,21 @@
import { CSSProperties } from "react";
export function ChineseIcon(props: { className?: string; style?: CSSProperties }) {
return (
<svg width="71px" height="48px" viewBox="0 0 71 48" version="1.1" xmlns="http://www.w3.org/2000/svg" className={props.className} style={props.style}>
<defs />
<g id="Flags" stroke="none" strokeWidth="1" fill="none" fillRule="evenodd" transform="translate(-70.000000, -498.000000)">
<g transform="translate(70.000000, 70.000000)" fillRule="nonzero" id="China">
<g transform="translate(0.000000, 428.000000)">
<rect id="Rounded_Rectangle_7_copy-5" fill="#ED5565" x="0.28" y="0.98" width="70" height="47" rx="6.36" />
<path d="M12.23,26.34 C11.41,26.93 10.93,26.6 11.16,25.61 L12.05,21.93 C12.2430284,20.8254147 11.8671738,19.6978512 11.05,18.93 L8.36,16.6 C7.59,15.94 7.79,15.37 8.8,15.34 L12.57,15.23 C13.6782653,15.1750168 14.6410409,14.4499636 15,13.4 L16.18,9.4 C16.47,8.4 16.98,8.4 17.32,9.4 L18.74,13.4 C19.1553515,14.4093082 20.1106424,15.0927684 21.2,15.16 L25.04,15.16 C26.04,15.16 26.25,15.73 25.49,16.39 L22.56,18.95 C21.7650096,19.7288598 21.4350484,20.866657 21.69,21.95 L22.62,25.19 C22.9,26.19 22.43,26.53 21.57,26 L18.42,24 C17.4584774,23.4711751 16.2849442,23.5095258 15.36,24.1 L12.23,26.34 Z" id="Shape_2_copy_9" fill="#F6D660"/>
<path d="M29.37,10.78 C29.09,10.98 28.93,10.87 29.01,10.52 L29.31,9.24 C29.3656763,8.87495864 29.2472583,8.50490228 28.99,8.24 L28.08,7.43 C27.82,7.2 27.89,7 28.23,6.99 L29.5,6.99 C29.8717689,6.9586152 30.1877729,6.70581199 30.3,6.35 L30.7,4.95 C30.8,4.61 30.97,4.61 31.09,4.95 L31.57,6.33 C31.7126147,6.67114428 32.031835,6.90575195 32.4,6.94 L33.7,6.94 C34.04,6.94 34.11,7.14 33.85,7.37 L32.85,8.26 C32.5912527,8.52348971 32.4790218,8.89759264 32.55,9.26 L32.87,10.39 C32.97,10.73 32.81,10.86 32.52,10.67 L31.46,10 C31.1505989,9.82136721 30.7694011,9.82136721 30.46,10 L29.37,10.78 Z" id="Shape_2_copy_10" fill="#F6D660"/>
<path d="M29.37,30.53 C29.09,30.73 28.93,30.62 29.01,30.27 L29.31,28.99 C29.3656763,28.6249586 29.2472583,28.2549023 28.99,27.99 L28.08,27.18 C27.82,26.95 27.89,26.75 28.23,26.74 L29.5,26.74 C29.8691682,26.7101752 30.1844554,26.4618866 30.3,26.11 L30.7,24.71 C30.8,24.37 30.97,24.37 31.09,24.71 L31.57,26.09 C31.7126147,26.4311443 32.031835,26.6657519 32.4,26.7 L33.7,26.7 C34.04,26.7 34.11,26.9 33.85,27.13 L32.85,28.02 C32.5912527,28.2834897 32.4790218,28.6575926 32.55,29.02 L32.87,30.15 C32.97,30.49 32.81,30.62 32.52,30.43 L31.47,29.76 C31.1605989,29.5813672 30.7794011,29.5813672 30.47,29.76 L29.37,30.53 Z" id="Shape_2_copy_11" fill="#F6D660"/>
<path d="M36.3,25.23 C36.02,25.43 35.86,25.32 35.94,24.98 L36.24,23.7 C36.2956763,23.3349586 36.1772583,22.9649023 35.92,22.7 L35.01,21.89 C34.75,21.66 34.82,21.46 35.16,21.45 L36.43,21.45 C36.7991682,21.4201752 37.1144554,21.1718866 37.23,20.82 L37.63,19.42 C37.73,19.08 37.9,19.08 38.02,19.42 L38.5,20.8 C38.6426147,21.1411443 38.961835,21.3757519 39.33,21.41 L40.63,21.41 C40.97,21.41 41.04,21.61 40.78,21.84 L39.78,22.73 C39.5248508,22.9954093 39.4164332,23.369263 39.49,23.73 L39.81,24.86 C39.91,25.2 39.74,25.33 39.46,25.14 L38.41,24.47 C38.1005989,24.2913672 37.7194011,24.2913672 37.41,24.47 L36.3,25.23 Z" id="Shape_2_copy_12" fill="#F6D660"/>
<path d="M36.3,16.09 C36.02,16.29 35.86,16.18 35.94,15.83 L36.24,14.55 C36.2956763,14.1849586 36.1772583,13.8149023 35.92,13.55 L35,12.7 C34.74,12.47 34.81,12.27 35.15,12.26 L36.42,12.26 C36.7891682,12.2301752 37.1044554,11.9818866 37.22,11.63 L37.62,10.23 C37.72,9.89 37.89,9.89 38.01,10.23 L38.49,11.61 C38.6326147,11.9511443 38.951835,12.1857519 39.32,12.22 L40.62,12.22 C40.96,12.22 41.03,12.42 40.77,12.65 L39.77,13.54 C39.5163739,13.8062871 39.4081897,14.1793363 39.48,14.54 L39.8,15.67 C39.9,16.01 39.73,16.14 39.45,15.95 L38.4,15.28 C38.0905989,15.1013672 37.7094011,15.1013672 37.4,15.28 L36.3,16.09 Z" id="Shape_2_copy_13" fill="#F6D660"/>
</g>
</g>
</g>
</svg>
);
}
@@ -65,10 +65,10 @@ export function ModsGrid({ modsMap, installed, modsSelected, onModChange, moreIn
<span className="z-10 sticky flex items-center justify-end top-0 bg-inherit border-b-2 border-main-color-1">
<BsmButton className="rounded-full h-6 w-6 p-[2px]" withBar={false} icon="search" onClick={handleToogleFilter} />
</span>
<span className="z-10 sticky top-0 flex items-center bg-inherit border-main-color-1 border-b-2 h-8 px-1">{filterEnabled ? <motion.input autoFocus className="bg-main-color-1 rounded-md h-6 px-2" initial={{ width: 0 }} animate={{ width: "250px" }} transition={{ ease: "easeInOut", duration: 0.15 }} onChange={e => handleInput(e.target.value)} /> : <span className="w-full text-center">{t("pages.version-viewer.mods.mods-grid.header-bar.name")}</span>}</span>
<span className="z-10 sticky flex items-center justify-center top-0 bg-inherit border-b-2 border-main-color-1 h-8 px-2">{t("pages.version-viewer.mods.mods-grid.header-bar.installed")}</span>
<span className="z-10 sticky flex items-center justify-center top-0 bg-inherit border-b-2 border-main-color-1 h-8 px-2">{t("pages.version-viewer.mods.mods-grid.header-bar.latest")}</span>
<span className="z-10 sticky flex items-center justify-center top-0 bg-inherit border-b-2 border-main-color-1 h-8">{t("pages.version-viewer.mods.mods-grid.header-bar.description")}</span>
<span className="z-10 sticky top-0 flex items-center bg-inherit border-main-color-1 border-b-2 h-8 px-1 whitespace-nowrap">{filterEnabled ? <motion.input autoFocus className="bg-main-color-1 rounded-md h-6 px-2" initial={{ width: 0 }} animate={{ width: "250px" }} transition={{ ease: "easeInOut", duration: 0.15 }} onChange={e => handleInput(e.target.value)} /> : <span className="w-full text-center">{t("pages.version-viewer.mods.mods-grid.header-bar.name")}</span>}</span>
<span className="z-10 sticky flex items-center justify-center top-0 bg-inherit border-b-2 border-main-color-1 h-8 px-2 whitespace-nowrap">{t("pages.version-viewer.mods.mods-grid.header-bar.installed")}</span>
<span className="z-10 sticky flex items-center justify-center top-0 bg-inherit border-b-2 border-main-color-1 h-8 px-2 whitespace-nowrap">{t("pages.version-viewer.mods.mods-grid.header-bar.latest")}</span>
<span className="z-10 sticky flex items-center justify-center top-0 bg-inherit border-b-2 border-main-color-1 h-8 whitespace-nowrap">{t("pages.version-viewer.mods.mods-grid.header-bar.description")}</span>
<span className="z-10 sticky top-0 bg-inherit border-b-2 border-main-color-1 h-8 flex justify-start items-center py-1 pl-[3px] min-w-[50px]">
<BsmDropdownButton className="h-full aspect-square relative rounded-full bg-light-main-color-1 dark:bg-main-color-3" withBar={false} icon="three-dots" buttonClassName="!rounded-full !p-[2px] !bg-light-main-color-2 dark:!bg-main-color-2 hover:!bg-light-main-color-1 dark:hover:!bg-main-color-3" menuTranslationY="5px" items={[{ text: "pages.version-viewer.mods.mods-grid.header-bar.dropdown.uninstall-all", icon: "trash", onClick: handleUninstallAll }]} />
</span>
@@ -3,13 +3,9 @@ export const defaultConfiguration: { [key in DefaultConfigKey]: any } = {
"second-color": "#ff4444",
theme: "os",
language: window.navigator.language.length <= 2 ? `${window.navigator.language}-${window.navigator.language.toLocaleUpperCase()}` : window.navigator.language,
supported_languages: ["en-US", "en-EN", "fr-FR", "es-ES", "de-DE", "ru-RU", "ja-JP"],
supported_languages: ["en-US", "en-EN", "fr-FR", "es-ES", "de-DE", "ru-RU", "zh-CN", "ja-JP"],
default_mods: ["SongCore", "WhyIsThereNoLeaderboard", "BeatSaverDownloader", "BeatSaverVoting", "PlaylistManager"],
"default-shared-folders": [
window.electron.path.join("Beat Saber_Data", "CustomLevels"),
window.electron.path.join("Beat Saber_Data", "CustomWIPLevels"),
"DLC"
],
"default-shared-folders": [window.electron.path.join("Beat Saber_Data", "CustomLevels"), window.electron.path.join("Beat Saber_Data", "CustomWIPLevels"), "DLC"],
};
export type DefaultConfigKey = "first-color" | "second-color" | "theme" | "language" | "supported_languages" | "default_mods" | "default-shared-folders";
@@ -58,7 +58,7 @@ export class SteamDownloaderService extends AbstractBsDownloaderService implemen
duration: 11_000,
title: "notifications.bs-download.steam-download.errors.titles.dotnet-required",
desc: "notifications.bs-download.steam-download.errors.msg.dotnet-required",
actions: [{ id: "0", title: "notifications.bs-download..errors.actions.download-dotnet" }],
actions: [{ id: "0", title: "notifications.bs-download.steam-download.errors.actions.download-dotnet" }],
});
if (choice === "0") {