bat file creates a "corrupt" zip

44 views Asked by At

I created a build.bat file to zip up the correct files for my browser extension and makes Firefox and Chromium builds. The problem is that, for some reason, these zips seem to be corrupt in some way.

@echo off
setlocal

:: Define variables
set ZIP_NAME_FIREFOX=Firefox.zip
set ZIP_NAME_CHROMIUM=Chromium.zip
set SOURCE_FOLDER=%CD%
set TEMP_FOLDER=%SOURCE_FOLDER%\temp

:: Ensure the temp folder is clean
if exist "%TEMP_FOLDER%" rmdir /s /q "%TEMP_FOLDER%"
mkdir "%TEMP_FOLDER%"

:: Copy files and folders individually to avoid cyclic copy
echo Copying files to the temp directory...
xcopy "%SOURCE_FOLDER%\mrbeastify.js" "%TEMP_FOLDER%" /Q
xcopy "%SOURCE_FOLDER%\manifest v3.json" "%TEMP_FOLDER%" /Q
xcopy "%SOURCE_FOLDER%\images" "%TEMP_FOLDER%\images\" /E /Q
xcopy "%SOURCE_FOLDER%\icons" "%TEMP_FOLDER%\icons\" /E /Q

echo Creating Firefox zip folder...
powershell Compress-Archive -Path "%SOURCE_FOLDER%\mrbeastify.js", "%SOURCE_FOLDER%\manifest.json", "%SOURCE_FOLDER%\images", "%SOURCE_FOLDER%\icons" -DestinationPath "%SOURCE_FOLDER%\%ZIP_NAME_FIREFOX%" -Force
echo Firefox zip folder created successfully.

:: Rename manifest for Chromium
echo Preparing files for Chromium zip...
rename "%TEMP_FOLDER%\manifest v3.json" "manifest.json"

echo Creating Chromium zip folder...
powershell Compress-Archive -Path "%TEMP_FOLDER%\mrbeastify.js", "%TEMP_FOLDER%\manifest.json", "%TEMP_FOLDER%\images", "%TEMP_FOLDER%\icons" -DestinationPath "%SOURCE_FOLDER%\%ZIP_NAME_CHROMIUM%" -Force
echo Chromium zip folder created successfully.

:: Cleanup
if exist "%TEMP_FOLDER%" rmdir /s /q "%TEMP_FOLDER%"

echo All operations completed successfully.
pause

When I zip the files manually, it works fine. I can load the extension temporarily and nothing goes wrong. When I use the build.bat file, and load the extension, my script cannot locate any of the images in the folders, and the extension icons also don't load.

I then decided to see what was up with the images, so I tried to delete the images folder inside the zip and replace it with a version known to work. Windows actually wasn't able to delete these folders (Luckily 7zip could). When I finally copied in the images and icons folders in manually, it all works.

What on earth could be going wrong here? I already checked whether the file was locked by some program (it wasn't), and whether running cmd as admin works (it doesn't).

0

There are 0 answers