Page 1 of 2

Colored Menu for starting multi task [SOLVED]

Posted: 17 Apr 2012 03:49
by abc0502
i'm making a batch file to install manual update to an online game so i'm missing one thing,
how can i ask to input to the location of a folder that has that update patches

This is the final Code and working fine Problem solved

Code: Select all

@echo off
Title Fiesta Manual Update Installer V3.0
::======================================================================
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
::======================================================================
mode 60,30
color 0
echo:&echo:&echo:&echo:&echo:&echo:&echo:&echo:&echo:&echo:
echo:     ######## #### ########  ######  ########    ###   
echo:     ##        ##  ##       ##    ##    ##      ## ##   
echo:     ##        ##  ##       ##          ##     ##   ## 
echo:     ######    ##  ######    ######     ##    ##     ##
echo:     ##        ##  ##             ##    ##    #########
echo:     ##        ##  ##       ##    ##    ##    ##     ##
echo:     ##       #### ########  ######     ##    ##     ##
echo:&echo:&echo:&echo:&echo:&echo:
call :color 0f "                         Enter                            "
pause >nul
cls
color 07

::======================================================================
:loop1
echo:&echo:&echo:&echo:&echo:
call :color 07 "            ==================================" &echo:
call :color 07 "            =" & call :color 0d "Fiesta Manual Update Installer" & call :color 07 "=" & echo:
call :color 07 "            ==================================" &echo:&echo:
call :color 0f "             Select An Option" &echo:&echo:&echo:
call :color 0a "                  (1) Auto Install" &echo:&echo:
call :color 0b "                  (2) Install Patches" &echo:&echo:
call :color 0e "                  (3) Install Sharplaunchers" &echo:&echo:
call :color 08 "                  (4) Exit" &echo:&echo:&echo:
set /p "cho1=Option #"
if %errorlevel%==1 cls & goto loop1
if %cho1%==1 goto auto
if %cho1%==2 goto patches
if %cho1%==3 goto sharplaunchers
if %cho1%==4 goto EOF
echo Invalid choice.
cls
goto loop1
::======================================================================
:auto
echo:
call :color 0c "Enter sharp launchers and patches Directory "&echo:
set /p "installpath=Dir:>"
if %errorlevel%==1 cls & goto loop1
call :color 04 "Installing Sharplaunchers and Patches ..."&echo:
if exist "%temp%\log.log" del /F /Q "%temp%\log.log" >nul
ping localhost -n 2 >nul

setlocal enableextensions
set log=%temp%\log.log
for /f "tokens=*" %%c in ('dir /b /on "%installpath%\*.*"') do (
echo %installpath%\%%c >>"%log%"
)
for /f "tokens=*" %%d in (%log%) do (
start "" /w "%%d"
)
msg * Auto Installation Completed.
msg * Please Restart Your Computer so Changes can take Effect.
cls
goto loop1
::======================================================================
:sharplaunchers
echo:
call :color 0c "Enter sharplaunchers Directory "&echo:
set /p "installpath=Dir:>"
if %errorlevel%==1 cls & goto loop1
call :color 04 "Installing Sharplaunchers ..."&echo:
if exist "%temp%\log.log" del /F /Q "%temp%\log.log" >nul
ping localhost -n 2 >nul

setlocal enableextensions
set log=%temp%\log.log
for /f "tokens=*" %%c in ('dir /b /on "%installpath%\*.*"') do (
echo %installpath%\%%c >>"%log%"
)
for /f "tokens=*" %%d in (%log%) do (
start "" /w "%%d"
)
msg * SharpLaunchers Installation Completed.
msg * Please Restart Your Computer so Changes can take Effect.
cls
goto loop1
::======================================================================
:patches
echo:
call :color 0c "Enter patches Directory "&echo:
set /p "installpath=Dir:>"
if %errorlevel%==1 cls & goto loop1
call :color 04 "Installing Patches ..."&echo:
if exist "%temp%\log.log" del /F /Q "%temp%\log.log" >nul
ping localhost -n 2 >nul

setlocal enableextensions
set log=%temp%\log.log
for /f "tokens=*" %%c in ('dir /b /on "%installpath%\*.*"') do (
echo %installpath%\%%c >>"%log%"
)
for /f "tokens=*" %%d in (%log%) do (
start "" /w "%%d"
)
msg * Patches Installation Completed.
cls
goto loop1
::======================================================================
:color
echo off
<nul set /p ".="%DEL% " " >> "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
::======================================================================

Re: specify a directory

Posted: 17 Apr 2012 04:46
by foxidrive
abc0502 wrote:i'm making a batch file to install manual update to an online game so i'm missing one thing,
how can i ask to input the location of a folder that has that update patches

i tried this to input the location but it keep run the next command directly without waiting for the input so it give errors:

:auto
Echo Enter Directory:
set "variable="
set /p "variable=install>"
if not defined variable goto :auto
Echo Installing Sharplaunchers and Patches ...
ping localhost -n 3 >nul
"%installpath%\SharpLauncher86b.exe"



Re: specify a directory

Posted: 17 Apr 2012 05:52
by abc0502
Thanks alot foxi for your replay but not all the code worked,only this worked

:auto
Echo Enter Directory:
set /p "variable=install>"
Echo Installing Sharplaunchers and Patches ...
ping localhost -n 3 >nul
"%installpath%\SharpLauncher86b.exe"

and it will look like that:

Code: Select all

:auto
Echo Enter Directory:
set /p "installpath=Directory>"
Echo Installing Sharplaunchers and Patches ...
ping localhost -n 3 >nul
"%installpath%\SharpLauncher86b.exe"

it geive errors for not finding the files then goto the start again
thanks :)

Re: specify a directory [solved]

Posted: 17 Apr 2012 06:04
by abc0502
one more thing :)
is there away to get the files "exe files" names and list them in alphapit order so the command install it one by one
and i don't have to add new patches name to the batch regulary, i tried using for command to get all files names to a log file then launche them one by one but "getting there names from the log file didn't work any idea

i tried using !k's Code for renaming and change it to start files but no luck:

Code: Select all

@echo off &setlocal enableextensions

set /a cnt=0
for /f "delims=" %%a in ('dir /b /on *.txt') do call :ren "%%a"
goto :eof

:ren
for /f "tokens=1" %%b in ('more +%cnt% log.log') do (
   ren %1 "%%b.txt"
   set /a cnt+=1 &goto :eof
)

Re: specify a directory

Posted: 17 Apr 2012 06:35
by abc0502
I used this but getting the more is not a command error !! :?:

Code: Select all

@echo off
cls
setlocal enableextensions
set path=%userprofile%\desktop\test
set /a cnt=0
for /f "delims=" %%a in ('dir /b /on "%path%\*.*"') do call :ren "%%a"
goto :eof

:ren
for /f "tokens=1" %%b in ('more +%cnt% log.log') do (
   "%%b.cmd"
   set /a cnt+=1 &goto :eof
)
pause

Re: specify a directory

Posted: 17 Apr 2012 07:16
by !k
set folder=%userprofile%\desktop\test

Re: specify a directory

Posted: 17 Apr 2012 07:29
by foxidrive
abc0502 wrote:Thanks alot foxi for your replay but not all the code worked,only this worked


When faced with an issue like this, try separating the function and see if it works.

My code below works fine in a subroutine of it's own.

Code: Select all

@echo off
:auto
Echo Enter Directory:
set "variable="
set /p "variable=install>"
if not defined variable goto :auto
echo "%variable%"
pause


Enter Directory:
install>abc def
"abc def"


Re: specify a directory

Posted: 19 Apr 2012 03:23
by abc0502
Thanks Foxidrive and !k for help :D :D :D
it worked and now i don't have to edit the batch on every new patches for the game
it read the folder containing the patches and make a list in alphapitc order then start every patch at a time.

i will post the code after small changes.
The batch will be in colors :evil:

Re: specify a directory

Posted: 19 Apr 2012 06:17
by abc0502
The First Code Was Modified with the working code

Re: specify a directory [SOLVED]

Posted: 19 Apr 2012 06:23
by foxidrive
You will get an error if the user enters nothing.

And %cho1% should be nulled before the set /p or it can take the value it had before the set /p, if enter was pressed.



set /p "cho1=Option #"
if %cho1%==1 goto auto
if %cho1%==2 goto patches
if %cho1%==3 goto sharplaunchers
if %cho1%==4 goto EOF
echo Invalid choice.
cls
goto loop1



Try this:

Code: Select all

@echo off
:auto
set "variable=zzz"
set /p "variable=press enter: "
if not defined variable goto :auto
echo "%variable%"
pause

Re: specify a directory [SOLVED]

Posted: 19 Apr 2012 07:01
by abc0502
WOW :roll: i didn't notice that thanks alot foxidrive ,
i changed the code now it work fine
and as u said in your last post i should used it from the begining :)

Re: specify a directory [SOLVED]

Posted: 19 Apr 2012 07:13
by foxidrive
This will not run any program in %%d.

start /w "%%d"


The first pair of quotes in a start command are used for the title.

You need this:

Code: Select all

start "" /w "%%d"

Re: specify a directory [SOLVED]

Posted: 19 Apr 2012 07:20
by abc0502
when i add

Code: Select all

if not defined %installpath% goto :loop1

nothing is installed or run
when i delete it every thing start normally why?

Re: specify a directory [SOLVED]

Posted: 19 Apr 2012 07:32
by abc0502
foxidrive wrote:This will not run any program in %%d.

start /w "%%d"


The first pair of quotes in a start command are used for the title.

You need this:

Code: Select all

start "" /w "%%d"

the folder that will be specified will have only patches that will be ordered in alphapitic order then will be run one by on the patches are auto start so the code work fine with this patches

Re: specify a directory [SOLVED]

Posted: 19 Apr 2012 07:39
by foxidrive
abc0502 wrote:when i add

Code: Select all

if not defined %installpath% goto :loop1

nothing is installed or run
when i delete it every thing start normally why?


if not defined installpath goto :loop1


Don't use quotes.