2022-03-05 04:49:14 +00:00
|
|
|
import React, { useContext } 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-05 04:49:14 +00:00
|
|
|
import { useAppDispatch } from "../lib/hooks";
|
|
|
|
import { clearPlugins, setPending } from "../slices/plugins";
|
2022-03-03 03:19:26 +00:00
|
|
|
import styles from "../styles/DataDirPicker.module.css";
|
|
|
|
|
|
|
|
export const excludedPlugins = [
|
|
|
|
"Skyrim.esm",
|
|
|
|
"Update.esm",
|
|
|
|
"Dawnguard.esm",
|
|
|
|
"HearthFires.esm",
|
|
|
|
"Dragonborn.esm",
|
|
|
|
];
|
|
|
|
|
|
|
|
type Props = {};
|
|
|
|
|
|
|
|
const DataDirPicker: React.FC<Props> = () => {
|
2022-03-05 04:49:14 +00:00
|
|
|
const workerPool = useContext(WorkerPoolContext);
|
2022-03-03 03:19:26 +00:00
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
2022-03-05 04:49:14 +00:00
|
|
|
const onDataDirButtonClick = async (event: {
|
|
|
|
target: { files: FileList | null };
|
|
|
|
}) => {
|
|
|
|
if (!workerPool) {
|
|
|
|
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
|
|
|
dispatch(clearPlugins());
|
|
|
|
const plugins = [];
|
2022-03-05 04:49:14 +00:00
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
|
|
const file = files[i];
|
2022-03-03 03:19:26 +00:00
|
|
|
if (
|
2022-03-05 04:49:14 +00:00
|
|
|
file.name.endsWith(".esp") ||
|
|
|
|
file.name.endsWith(".esm") ||
|
|
|
|
file.name.endsWith(".esl")
|
2022-03-03 03:19:26 +00:00
|
|
|
) {
|
2022-03-05 04:49:14 +00:00
|
|
|
plugins.push(file);
|
2022-03-03 03:19:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dispatch(setPending(plugins.length));
|
|
|
|
|
2022-03-03 06:33:36 +00:00
|
|
|
plugins.forEach(async (plugin, index) => {
|
2022-03-05 04:49:14 +00:00
|
|
|
const contents = new Uint8Array(await plugin.arrayBuffer());
|
2022-03-03 03:19:26 +00:00
|
|
|
try {
|
2022-03-05 04:49:14 +00:00
|
|
|
workerPool.pushTask({
|
|
|
|
skipParsing: excludedPlugins.includes(plugin.name),
|
|
|
|
filename: plugin.name,
|
|
|
|
lastModified: plugin.lastModified,
|
|
|
|
contents,
|
|
|
|
});
|
2022-03-03 03:19:26 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
2022-03-03 06:33:36 +00:00
|
|
|
});
|
2022-03-03 03:19:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<p className={styles["no-top-margin"]}>
|
|
|
|
To see all of the cell edits and conflicts for your current mod load
|
|
|
|
order select your <code>Data</code> directory below to load the plugins.
|
|
|
|
</p>
|
2022-03-05 04:49:14 +00:00
|
|
|
<input
|
|
|
|
type="file"
|
|
|
|
webkitdirectory=""
|
|
|
|
onChange={onDataDirButtonClick}
|
|
|
|
disabled={!workerPool}
|
|
|
|
/>
|
2022-03-03 03:19:26 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DataDirPicker;
|