2022-03-09 06:35:20 +00:00
|
|
|
import React, { useContext, useRef, useState, useEffect } from "react";
|
2022-03-03 03:19:26 +00:00
|
|
|
|
2022-03-05 04:53:36 +00:00
|
|
|
import { WorkerPoolContext } from "../lib/WorkerPool";
|
2022-03-09 06:35:20 +00:00
|
|
|
import { useAppSelector } from "../lib/hooks";
|
|
|
|
import { isPlugin, parsePluginFiles } from "../lib/plugins";
|
2022-03-03 03:19:26 +00:00
|
|
|
import styles from "../styles/DataDirPicker.module.css";
|
|
|
|
|
|
|
|
type Props = {};
|
|
|
|
|
|
|
|
const DataDirPicker: React.FC<Props> = () => {
|
2022-03-05 04:49:14 +00:00
|
|
|
const workerPool = useContext(WorkerPoolContext);
|
2022-03-09 06:35:20 +00:00
|
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
|
|
const plugins = useAppSelector((state) => state.plugins.plugins);
|
|
|
|
const pluginsPending = useAppSelector((state) => state.plugins.pending);
|
|
|
|
const [loading, setLoading] = useState<boolean>(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (pluginsPending === 0 && loading) {
|
|
|
|
setLoading(false);
|
|
|
|
} else if (pluginsPending > 0 && !loading) {
|
|
|
|
setLoading(true);
|
|
|
|
}
|
|
|
|
}, [pluginsPending, loading, setLoading]);
|
2022-03-03 03:19:26 +00:00
|
|
|
|
2022-03-09 06:35:20 +00:00
|
|
|
// It would be nice to open the directory with window.showDirectoryPicker() in supported browsers,
|
|
|
|
// but it does not allow selecting directories under C:\\Program Files and it does not throw any error
|
|
|
|
// that I can catch here when a user tries to select it, so it's basically useless. So instead, I have
|
|
|
|
// to use this non-standard webkitdirectory input attribute that loads all files in a directory instead
|
|
|
|
// of just selecting the directory itself. Yay.
|
2022-03-05 04:49:14 +00:00
|
|
|
const onDataDirButtonClick = async (event: {
|
|
|
|
target: { files: FileList | null };
|
|
|
|
}) => {
|
2022-03-19 05:20:24 +00:00
|
|
|
if (!workerPool || workerPool.availableWorkers.length === 0) {
|
2022-03-05 04:49:14 +00:00
|
|
|
return alert("Workers not loaded yet");
|
2022-03-03 03:19:26 +00:00
|
|
|
}
|
2022-03-05 04:49:14 +00:00
|
|
|
const files = event.target.files ?? [];
|
2022-03-03 03:19:26 +00:00
|
|
|
const plugins = [];
|
2022-03-05 04:49:14 +00:00
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
|
|
const file = files[i];
|
2022-03-09 06:35:20 +00:00
|
|
|
if (isPlugin(file)) {
|
2022-03-05 04:49:14 +00:00
|
|
|
plugins.push(file);
|
2022-03-03 03:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-09 06:35:20 +00:00
|
|
|
parsePluginFiles(plugins, workerPool);
|
2022-03-03 03:19:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-03-19 20:29:06 +00:00
|
|
|
<p>
|
|
|
|
<strong className={styles.step}>1. </strong>Select or drag-and-drop your
|
|
|
|
Skyrim{" "}
|
2022-03-15 23:59:16 +00:00
|
|
|
<strong>
|
|
|
|
<code>Data</code>
|
|
|
|
</strong>{" "}
|
2022-03-16 02:33:44 +00:00
|
|
|
folder below to load the plugins and see all of the cell edits and
|
2022-03-15 23:59:16 +00:00
|
|
|
conflicts for your current mod load order.
|
2022-03-16 02:33:44 +00:00
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
The Data folder can be found in the installation directory of the game.
|
2022-03-03 03:19:26 +00:00
|
|
|
</p>
|
2022-03-05 04:49:14 +00:00
|
|
|
<input
|
|
|
|
type="file"
|
|
|
|
webkitdirectory=""
|
|
|
|
onChange={onDataDirButtonClick}
|
2022-03-09 06:35:20 +00:00
|
|
|
style={{ display: "none" }}
|
|
|
|
ref={inputRef}
|
2022-03-05 04:49:14 +00:00
|
|
|
/>
|
2022-03-09 06:35:20 +00:00
|
|
|
{/* input webkitdirectory is buggy, so keep it hidden and control it through a normal button */}
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
if (inputRef.current) {
|
|
|
|
inputRef.current.value = ""; // clear the value so reloading same directory works
|
|
|
|
inputRef.current.click();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
disabled={!workerPool || loading}
|
|
|
|
>
|
|
|
|
{loading ? "Loading" : plugins.length > 0 ? "Reload" : "Open"} Skyrim
|
|
|
|
Data directory
|
|
|
|
</button>
|
2022-03-03 03:19:26 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DataDirPicker;
|