Skip to content

Commit

Permalink
fix batch
Browse files Browse the repository at this point in the history
  • Loading branch information
hliebscher committed Jul 25, 2023
1 parent 533830b commit bf21d2a
Showing 1 changed file with 112 additions and 30 deletions.
142 changes: 112 additions & 30 deletions resources/profiles/create_json.bat
Original file line number Diff line number Diff line change
@@ -1,48 +1,133 @@
@echo off
setlocal enabledelayedexpansion

REM Funktion zum Durchsuchen eines bestimmten Unterverzeichnisses und Erstellen der JSON-Struktur
:: Funktion zum Durchsuchen eines bestimmten Unterverzeichnisses und Erstellen der JSON-Struktur
:explore_filament
setlocal EnableDelayedExpansion
set "dir=%~1"
set "subdir=%~2"
set "indent=%~3"
set "fdm_files_common="
for /f "delims=" %%F in ('dir /b /a-d "%dir%\fdm_filament_common.json" 2^>nul ^| sort') do (
set "fdm_files_common=!fdm_files_common!%%F "
)
set "fdm_files="
for /f "delims=" %%F in ('dir /b /a-d "%dir%\fdm*.json" ^| find /v "fdm_filament_common.json" ^| sort') do (
set "fdm_files=!fdm_files!%%F "
)
set "other_files="
for /f "delims=" %%F in ('dir /b /a-d "%dir%\*.json" ^| find /v "fdm*.json" ^| sort') do (
set "other_files=!other_files!%%F "
)
set "json_string="
set "leer= "

for /f "delims=" %%F in ('dir /b /a-d "%dir%\fdm_filament_common.json"') do (
set "fdm_files_common=!fdm_files_common!%dir%\%%F,"
for %%F in (%fdm_files_common%) do (
call :set_json_string "%%F"
)

for /f "delims=" %%F in ('dir /b /a-d "%dir%\fdm*.json" ^| findstr /v /i "fdm_filament_common.json"') do (
set "fdm_files=!fdm_files!%dir%\%%F,"
for %%F in (%fdm_files%) do (
call :set_json_string "%%F"
)

for /f "delims=" %%F in ('dir /b /a-d "%dir%\*.json" ^| findstr /v /i "fdm*.json"') do (
set "other_files=!other_files!%dir%\%%F,"
for %%F in (%other_files%) do (
call :set_json_string "%%F"
)
if defined json_string (
set "json_string=!json_string:~0,-3!"
)
echo %indent%[
echo -e %json_string%
echo %indent%]
goto :eof

:explore_process
setlocal EnableDelayedExpansion
set "dir=%~1"
set "subdir=%~2"
set "indent=%~3"
set "fdm_files_common="
for /f "delims=" %%F in ('dir /b /a-d "%dir%\fdm_process_common.json" 2^>nul ^| sort') do (
set "fdm_files_common=!fdm_files_common!%%F "
)
set "fdm_files="
for /f "delims=" %%F in ('dir /b /a-d "%dir%\fdm*.json" ^| find /v "fdm_process_common.json" ^| sort') do (
set "fdm_files=!fdm_files!%%F "
)
set "other_files="
for /f "delims=" %%F in ('dir /b /a-d "%dir%\( *.json" ^| find /v "fdm*.json" ^| sort') do (
set "other_files=!other_files!%%F "
)
set "json_string="
set "leer= "
for %%F in (%fdm_files_common%) do (
call :set_json_string "%%F"
)

for %%F in (%fdm_files%) do (
call :set_json_string "%%F"
)

for %%F in (%other_files%) do (
call :set_json_string "%%F"
)
if defined json_string (
set "json_string=!json_string:~0,-3!"
)
echo %indent%[
echo -e %json_string%
echo %indent%]
goto :eof

:explore_machine_model_list
setlocal EnableDelayedExpansion
set "dir=%~1"
set "subdir=%~2"
set "indent=%~3"
set "files="
for /f "delims=" %%F in ('dir /b /a-d "%dir%\*.json" ^| find /v "( *" ^| find /v "fdm*" ^| sort') do (
set "files=!files!%%F "
)
set "json_string="
set "leer= "
for %%F in (%files%) do (
call :set_json_string "%%F"
)
if defined json_string (
set "json_string=!json_string:~0,-1!" REM Entferne das letzte Komma
set "json_string=!json_string:~0,-3!"
)
echo %indent%[
echo -e %json_string%
echo %indent%]
goto :eof

:explore_machine
setlocal EnableDelayedExpansion
set "dir=%~1"
set "subdir=%~2"
set "indent=%~3"
set "fdm_files_common="
for /f "delims=" %%F in ('dir /b /a-d "%dir%\fdm_machine_common.json" 2^>nul ^| sort') do (
set "fdm_files_common=!fdm_files_common!%%F "
)
set "fdm_files="
for /f "delims=" %%F in ('dir /b /a-d "%dir%\fdm*.json" ^| find /v "fdm_machine_common.json" ^| sort') do (
set "fdm_files=!fdm_files!%%F "
)
set "other_files="
for /f "delims=" %%F in ('dir /b /a-d "%dir%\( *.json" ^| find /v "fdm*.json" ^| sort') do (
set "other_files=!other_files!%%F "
)
set "json_string="
set "leer= "
for %%F in (%fdm_files_common%) do (
call :set_json_string "%%F"
)
for %%F in (%fdm_files%) do (
call :set_json_string "%%F"
)
for %%F in (%other_files%) do (
call :set_json_string "%%F"
)
if defined json_string (
set "json_string=!json_string:~0,-3!"
)
echo %indent%[
echo %json_string%
echo -e %json_string%
echo %indent%]
goto :eof

Expand All @@ -52,27 +137,24 @@ set "filename=%~nx1"
set "filename_without_extension=%~n1"
set "directory_path=%~dp1"
set "extension=%~x1"
set "filename=%filename: =_%"
set "name=!filename:~0,-5!"
set "json_string=!json_string!!indent!{"
set "json_string=!json_string!"name": "!name!","
set "json_string=!json_string!"sub_path": "%subdir%\!filename!""
set "json_string=!json_string!},"
set "name=%filename_without_extension:.=%"
set "json_string=%indent%{"
set "json_string=%json_string%\"name\": \"%filename_without_extension%,\""
set "json_string=%json_string%\"sub_path\": \"%subdir%\%filename%\""
set "json_string=%json_string%},"
goto :eof


REM explore_process und explore_machine_model_list sind analog zu explore_filament, aber mit entsprechendem Namen.
REM (Wird nicht weiter oben wiederholt, um den Text kompakt zu halten.)

REM Hauptskript zum Erstellen der snapmaker.json-Datei
:: Hauptskript zum Erstellen der snapmaker.json-Datei
:main
set "base_directory=%~1"
set "json_filename=%~1.json"
set "counter=1"

REM while exist "%json_filename%" (
REM set /a counter+=1
REM set "json_filename=%~1_!counter!.json"
REM )
:: Uncomment the following block if you want to add numbering to the json_filename
:::while exist "%json_filename%" (
::: set /a "counter+=1"
::: set "json_filename=%~1_!counter!.json"
:::)

if not exist "%base_directory%" (
echo Das Verzeichnis %base_directory% existiert nicht.
Expand Down

0 comments on commit bf21d2a

Please sign in to comment.