2022-03-09 06:35:20 +00:00
|
|
|
import React, { useContext, useRef, useState, useEffect } from "react";
|
2022-04-29 02:48:31 +00:00
|
|
|
import Cookies from "js-cookie";
|
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";
|
2022-04-29 02:48:31 +00:00
|
|
|
import { createPortal } from "react-dom";
|
2022-03-03 03:19:26 +00:00
|
|
|
|
|
|
|
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);
|
2022-08-18 03:19:55 +00:00
|
|
|
const plugins = useAppSelector((state) => state.plugins.parsedPlugins);
|
2022-03-09 06:35:20 +00:00
|
|
|
const pluginsPending = useAppSelector((state) => state.plugins.pending);
|
|
|
|
const [loading, setLoading] = useState<boolean>(false);
|
2022-04-29 02:48:31 +00:00
|
|
|
const [uploadNoticeShown, setUploadNoticeShown] = useState(false);
|
|
|
|
const [ignoreUploadNoticeChecked, setIgnoreUploadNoticeChecked] =
|
|
|
|
useState(false);
|
2022-03-09 06:35:20 +00:00
|
|
|
|
|
|
|
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-19 21:49:33 +00:00
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
For Mod Organizer users, select the mod directory located at{" "}
|
|
|
|
<strong>
|
|
|
|
<code className={styles["break-word"]}>
|
|
|
|
C:\Users\username\AppData\Local\ModOrganizer\Skyrim Special
|
|
|
|
Edition\mods
|
|
|
|
</code>
|
|
|
|
</strong>
|
|
|
|
.
|
2022-03-03 03:19:26 +00:00
|
|
|
</p>
|
2022-04-29 02:48:31 +00:00
|
|
|
{typeof window !== "undefined" &&
|
|
|
|
createPortal(
|
|
|
|
<dialog open={uploadNoticeShown} className={styles.dialog}>
|
|
|
|
<p>
|
|
|
|
<strong>NOTE:</strong> the following dialog will ask you to upload
|
|
|
|
all the files in your Data folder.
|
|
|
|
<strong>NOTHING WILL BE UPLOADED ANYWHERE</strong>. The plugin
|
|
|
|
files will only be transferred to your browser and processed on
|
|
|
|
your device.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Drag and drop the Data folder onto the web page to avoid the
|
|
|
|
upload dialog entirely.
|
|
|
|
</p>
|
|
|
|
<label>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
id="ignore-upload-notice"
|
|
|
|
checked={ignoreUploadNoticeChecked}
|
|
|
|
onChange={(event) => {
|
|
|
|
if (event.target.checked) {
|
|
|
|
setIgnoreUploadNoticeChecked(true);
|
|
|
|
} else {
|
|
|
|
setIgnoreUploadNoticeChecked(false);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>{" "}
|
|
|
|
Don't show this message again
|
|
|
|
</label>
|
|
|
|
<menu>
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
setUploadNoticeShown(false);
|
|
|
|
if (ignoreUploadNoticeChecked) {
|
|
|
|
Cookies.set("ignoreDataDirPickerUploadNotice", "true");
|
|
|
|
}
|
|
|
|
if (inputRef.current) {
|
|
|
|
inputRef.current.click();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
Ok
|
|
|
|
</button>
|
|
|
|
</menu>
|
|
|
|
</dialog>,
|
|
|
|
document.body
|
|
|
|
)}
|
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
|
2022-04-29 02:48:31 +00:00
|
|
|
if (Cookies.get("ignoreDataDirPickerUploadNotice") !== "true") {
|
|
|
|
setUploadNoticeShown(true);
|
|
|
|
} else {
|
|
|
|
inputRef.current.click();
|
|
|
|
}
|
2022-03-09 06:35:20 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
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;
|