Skip to content

Commit

Permalink
Improve warning about output directory matching pre-extracted data di…
Browse files Browse the repository at this point in the history
…rectory.
  • Loading branch information
olegbl committed Oct 14, 2024
1 parent c8b6e56 commit 3968441
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
38 changes: 26 additions & 12 deletions src/renderer/react/ModManagerSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BridgeAPI from 'renderer/BridgeAPI';
import { useDataPath } from 'renderer/react/context/DataPathContext';
import { useExtraGameLaunchArgs } from 'renderer/react/context/ExtraGameLaunchArgsContext';
import {
useGamePath,
Expand Down Expand Up @@ -77,6 +78,8 @@ export default function ModManagerSettings(_props: Props): JSX.Element {
usePreExtractedDataPath();
const [outputModName, setOutputModName] = useOutputModName();
const mergedPath = useOutputPath();
const dataPath = useDataPath();
const outputPath = isDirectMode ? dataPath : mergedPath;

const [themeMode, setThemeMode] = useThemeMode();

Expand All @@ -97,6 +100,9 @@ export default function ModManagerSettings(_props: Props): JSX.Element {
),
) ?? true;

const isIdenticalInputAndOutput =
preExtractedDataPath.toLowerCase() === outputPath.toLowerCase();

const {
nexusApiState,
nexusAuthState,
Expand All @@ -107,14 +113,24 @@ export default function ModManagerSettings(_props: Props): JSX.Element {
unregisterAsNxmProtocolHandler,
} = useNexusAuthState();

console.log(
'DEBUG',
preExtractedDataPath.toLowerCase(),
outputPath.toLowerCase(),
);

return (
<List
disablePadding={true}
sx={{ width: '100%', flex: 1, overflow: 'auto', border: 'none' }}
>
<StyledAccordion
defaultExpanded={
useRef(!isValidGamePath || !isValidPreExtractedDataPath).current
useRef(
!isValidGamePath ||
!isValidPreExtractedDataPath ||
isIdenticalInputAndOutput,
).current
}
disableGutters={true}
elevation={0}
Expand Down Expand Up @@ -185,15 +201,13 @@ export default function ModManagerSettings(_props: Props): JSX.Element {
value={preExtractedDataPath}
variant="filled"
/>
{isDirectMode &&
preExtractedDataPath === `${rawGamePath}\\data` ? (
<Alert severity="warning">
It looks like you are using direct mode and are setting the
source Data Directory to the &quot;data&quot; folder in the
game&apos;s installation directory. Are you{' '}
<strong>sure</strong> you want to do this? You will be reading
the vanilla state of the game&apos;s files from the same
directory that D2RMM will install mods to.
{isIdenticalInputAndOutput ? (
<Alert severity="error">
It looks like you are reading pre-extracted game data from the
same directory that D2RMM will generate output modded files
into ("{outputPath}"). Are you <strong>sure</strong> you want
to do this? This will most likely lead to completely broken
behavior.
</Alert>
) : null}
</>
Expand All @@ -217,7 +231,7 @@ export default function ModManagerSettings(_props: Props): JSX.Element {
variant="filled"
/>
<Typography color="text.secondary" variant="subtitle2">
Generated files will be located in &ldquo;{mergedPath}\&rdquo;.
Generated files will be located in &ldquo;{outputPath}\&rdquo;.
</Typography>
<Typography color="text.secondary" variant="subtitle2">
Save game files will be located in &ldquo;%UserProfile%\Saved
Expand Down Expand Up @@ -272,7 +286,7 @@ export default function ModManagerSettings(_props: Props): JSX.Element {
</ListItemButton>
{!isDirectMode ? null : (
<Typography color="text.secondary" variant="subtitle2">
Generated files will be located in &ldquo;{gamePath}\data\&rdquo;.
Generated files will be located in &ldquo;{outputPath}\&rdquo;.
</Typography>
)}
<Alert severity="warning">
Expand Down
15 changes: 12 additions & 3 deletions src/renderer/react/hooks/useSavedState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ export default function useSavedState<T>(
deserialize: (value: string) => T = deserializeImplicit,
): [T, React.Dispatch<React.SetStateAction<T>>] {
const [value, setValue] = useState<T>(() => {
const savedValue = localStorage.getItem(key);
return savedValue != null ? deserialize(savedValue) : initialValue;
try {
const savedValue = localStorage.getItem(key);
return savedValue != null ? deserialize(savedValue) : initialValue;
} catch (e) {
console.error(e);
return initialValue;
}
});

useEffect(() => {
localStorage.setItem(key, serialize(value));
try {
localStorage.setItem(key, serialize(value));
} catch (e) {
console.error(e);
}
}, [key, value, serialize]);

return [value, setValue];
Expand Down

0 comments on commit 3968441

Please sign in to comment.