Advertisement
jargon

"Dev History Ripper\Ripper.cmd"

Jan 11th, 2025 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.49 KB | Gaming | 0 0
  1. :: "Dev History Ripper\Ripper.cmd"
  2.  
  3. @echo off
  4. setlocal EnableDelayedExpansion
  5.  
  6. :: Ensure the temp directory exists
  7. if not exist ".\temp" mkdir ".\temp"
  8.  
  9. :: Cleanup previous temporary files
  10. call :wipe
  11.  
  12. :: Execute clone, sort, and process phases
  13. call :clone
  14. call :process
  15.  
  16. :: Generate final output file
  17. type ".\temp\process.temp" > ".\DEVNOTES.md"
  18.  
  19. :: Uncomment the following line to clean temp files after processing
  20. call :wipe
  21.  
  22. exit /b
  23.  
  24. :wipe
  25. :: Define temp files to delete
  26. set "files=clone sort process"
  27. for %%f in (%files%) do (
  28.     if exist ".\temp\%%f.temp" (
  29.         del ".\temp\%%f.temp" /f /q
  30.     )
  31. )
  32. exit /b
  33.  
  34. :clone
  35. :: Gather all matching files and output to clone.temp
  36. type nul > ".\temp\clone.temp"
  37. dir "f:\?*.puzzlum.?*.test ????-????-???? (?*).7z" /aa /b >> ".\temp\clone.temp"
  38. dir "..\?*.puzzlum.?*.test ????-????-???? (?*).7z" /aa /b >> ".\temp\clone.temp"
  39.  
  40. :: Sort the file list and remove duplicates
  41. sort ".\temp\clone.temp" /r /unique > ".\temp\sort.temp"
  42. exit /b
  43.  
  44. :process
  45.  
  46. :: Initialize the output file
  47. type nul > ".\temp\process.temp"
  48. setlocal enabledelayedexpansion
  49.  
  50. :: Process each line from the sorted file list
  51. set "previous="
  52. set /a count = 0
  53.  
  54. :: Process each line from the sorted file list
  55. for /f "usebackq delims=" %%A in (".\temp\sort.temp") do (
  56.    
  57.     set /a count = count + 1
  58.    
  59.     set "line=%%A"
  60.  
  61.     :: Default values for parsing
  62.     set "prefix="
  63.     set "timestamp="
  64.     set "comment="
  65.  
  66.     :: Extract fields with robust parsing
  67.     for /f "tokens=1* delims= " %%B in ("!line!") do (
  68.         set "prefix=%%B"
  69.         set "remainder=%%C"
  70.     )
  71.     for /f "tokens=1* delims= " %%D in ("!remainder!") do (
  72.         set "timestamp=%%D"
  73.         set "comment=%%E"
  74.     )
  75.  
  76.     :: Validate timestamp length
  77.     if "!timestamp!" neq "" if "!timestamp:~0,4!" lss "1000" (
  78.         echo Skipping invalid line: !line!
  79.         rem endlocal
  80.         goto :continue
  81.     )
  82.  
  83.     :: Cleanup and format comment
  84.     set "comment=!comment:.7z=!"
  85.     set "comment=!comment:~1,-1!"
  86.  
  87.     :: Reformat timestamp
  88.     set "converted=!timestamp:~0,4! !timestamp:~5,2!/!timestamp:~7,2! !timestamp:~10,2!:!timestamp:~12,2!"
  89.  
  90.     set "dispheader=1"
  91.    
  92.     :: Check if the prefix has changed
  93.     if /i "!prefix!" neq "!previous!" (
  94.         set "header=### !converted! !count!: !prefix!"
  95.         echo Writing new header: !header!
  96.         echo !header! >> ".\temp\process.temp"
  97.         set "previous=!prefix!"
  98.     )
  99.    
  100.     :: Write the processed line
  101.     set "line=-- **!converted! !count!: "!comment!"**"
  102.     echo Writing line: !line!
  103.     echo !line! >> ".\temp\process.temp"
  104.    
  105. :continue
  106.     endlocal
  107. )
  108. exit /b
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement