Skip to content

Commit

Permalink
warn when checking gzip
Browse files Browse the repository at this point in the history
  • Loading branch information
alextusinean committed Jul 2, 2024
1 parent 3ac152d commit 8a94855
Showing 1 changed file with 46 additions and 9 deletions.
55 changes: 46 additions & 9 deletions components/cryptForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,20 @@ export default function CryptForm({ isEncryption, isLoading, setIsLoading, passw
const saveFileRef = useRef();
const [data, setData] = useState(null);
const [shouldGzip, setShouldGzip] = useState(false);
const { isOpen, onOpen, onClose } = useDisclosure();
const [isEncryptionWarning, setIsEncryptionWarning] = useState(false);
const { isOpen, onOpen: _onOpen, onClose: _onClose } = useDisclosure();

const onOpen = (encryption) => {
if (encryption)
setIsEncryptionWarning(true);

_onOpen();
};

const onClose = () => {
_onClose();
setIsEncryptionWarning(false);
};

const download = () => {
setData(null);
Expand Down Expand Up @@ -82,7 +95,20 @@ export default function CryptForm({ isEncryption, isLoading, setIsLoading, passw
fileReader.readAsArrayBuffer(changeEvent.target.files[0]);
}}
/>
{isEncryption && <Checkbox disabled={isLoading} isChecked={shouldGzip} onChange={e => setShouldGzip(e.target.checked)}>GZip</Checkbox>}
{isEncryption && (
<Checkbox
disabled={isLoading}
isChecked={shouldGzip}
onChange={e => {
if (!e.target.checked)
setShouldGzip(false);
else
onOpen(true);
}}
>
GZip
</Checkbox>
)}
</Box>
<div width='100%'></div>

Expand Down Expand Up @@ -184,22 +210,33 @@ export default function CryptForm({ isEncryption, isLoading, setIsLoading, passw
<ModalHeader color='orange'>Warning!</ModalHeader>
<ModalCloseButton />
<ModalBody>
<Text>
Your save file was also GUnZipped (decompressed). This means that when you are done editing your save file
and want to re-encrypt it, you will have to check the GZip checkbox before so the file can also be re-compressed.
Unless you check the box, the save file might not be recognized by the game and might be deleted.
</Text>
{isEncryptionWarning ? (
<Text>
You should only check this box if you were warned that the save file was GUnZipped too when you decrypted it.
If you GZip a save file that isn't supposed to be GZipped, the game might not recognize it and might delete it.
</Text>
) : (
<Text>
Your save file was also GUnZipped (decompressed). This means that when you are done editing your save file
and want to re-encrypt it, you will have to check the GZip checkbox before so the file can also be re-compressed.
Unless you check the box, the save file might not be recognized by the game and might be deleted.
</Text>
)}
</ModalBody>

<ModalFooter>
<Button
colorScheme='teal'
onClick={() => {
download();
if (isEncryptionWarning)
setShouldGzip(true);
else
download();

onClose();
}}
>
Ok, proceed to download
Ok, proceed{!isEncryptionWarning ? ' with download' : ''}
</Button>
</ModalFooter>
</ModalContent>
Expand Down

0 comments on commit 8a94855

Please sign in to comment.