Skip to content

Fix replace.bat when CWD is wrong; alert on unknown firmware build#10

Open
TitaniumKnight1 wants to merge 1 commit intoKindleModding:mainfrom
TitaniumKnight1:fix/replace-bat-cwd-and-offset-alert
Open

Fix replace.bat when CWD is wrong; alert on unknown firmware build#10
TitaniumKnight1 wants to merge 1 commit intoKindleModding:mainfrom
TitaniumKnight1:fix/replace-bat-cwd-and-offset-alert

Conversation

@TitaniumKnight1
Copy link
Copy Markdown

Problem

  • replace.bat used for /r ".", so if the batch was started with the wrong working directory (e.g. Run as administrator → often System32), no details.html files were found and copies were silent (>nul).
  • On device, if the software build ID was missing from offsets, the script threw after the first alert with no clear reason.

Changes

  • Recurse from %~dp0 so the tree is always anchored to the folder that contains replace.bat and adbreak.html.
  • Print each replaced path and a total count, or an explicit message when zero files are found.
  • If the build ID is not in offsets, show an alert instead of failing silently.
  • guide.txt: note the expected console output.
  • Add a minimal .gitignore for common Windows junk files.

Copilot AI review requested due to automatic review settings March 23, 2026 00:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves reliability and debuggability of the AdBreak workflow by making the Windows replacement script independent of the current working directory and by adding a clear user-facing alert when the current Kindle build ID is not present in the offset table.

Changes:

  • Anchor replace.bat’s recursive search to the script directory (%~dp0) and print per-file replacements plus a final summary.
  • Add a missing-offset guard in adbreak.html to alert on unsupported/unknown build IDs.
  • Update guide.txt with expected Windows output and add a minimal Windows-focused .gitignore.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
adbreak/replace.bat Makes the replacement scan deterministic regardless of CWD and adds console output + counts.
adbreak/guide.txt Documents the new Windows script behavior/output so users know what to expect.
adbreak/adbreak.html Adds a clear unsupported-build alert before dereferencing missing offset entries.
.gitignore Ignores common Windows metadata files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +20
for /r "%_root%" %%F in (details.html) do (
if exist "%%~fF" (
copy /y "%~dp0adbreak.html" "%%~fF" >nul
copy /y "%_root%adbreak.html" "%%~fF" >nul
if not errorlevel 1 (
set /a _count+=1
echo Replaced: %%~fF
)
)
)
if !_count! equ 0 (
echo No details.html files found under:
echo %_root%
echo Put replace.bat next to adbreak.html inside your copied .assets tree, then run again.
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The final summary uses _count (successful copies) to decide whether to print "No details.html files found". If details.html files exist but the copy fails (e.g., adbreak.html missing or permissions issue), _count stays 0 and the script reports that no files were found, which is misleading. Consider separately counting matches vs. successful replacements and/or checking %_root%adbreak.html exists up front; also emit an explicit error when a copy fails so users can diagnose why nothing was replaced.

Copilot uses AI. Check for mistakes.
Comment on lines +2 to +7
setlocal EnableDelayedExpansion
rem Always search from this script's folder. "Run as administrator" and some
rem launch methods leave the current directory as System32, so for /r "."
rem would find nothing and fail silently.
set "_root=%~dp0"
set /a _count=0
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EnableDelayedExpansion isn't needed here (you never read _count inside the for block), and it can break when %~dp0 or any matched path contains ! (literal exclamation marks get treated as delayed-expansion delimiters after %_root% is expanded). Consider dropping delayed expansion and using %_count% for the final summary (or enabling delayed expansion only in the narrowest scope where it's required).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants