Computer Hope

Microsoft => Microsoft DOS => Topic started by: millergram on July 26, 2014, 02:21:53 AM

Title: A batch based profile manager GUI
Post by: millergram on July 26, 2014, 02:21:53 AM
Hello all I have decided to brush up on my batch skills a bit and do something new to make me think a bit; so im just gonna share the experience with you guys as I go about it. Although im already a quarter of the way done (mabey)

Below is the code I have completed so far. Feel free to see if there is anything you have seen before and comment on below.

Code: [Select]
@Echo off
:start
mkdir "%appdata%\Millergram Morrowind Profile Manager"
mkdir "%appdata%\Millergram Morrowind Profile Manager\Profiles"
set Prf=%appdata%\Millergram Morrowind Profile Manager\Profiles
set dtr=%appdata%\Millergram Morrowind Profile Manager\Data
cls
Rem By Millergram

Title DIY Morrowind Profile Manager

Rem These Lines Check for A config file listing current profiles and creates one if does not exist

pushd "%dtr%"
if not exist Profiles.cfg (
Echo.>Profiles.cfg)
popd

Rem These lines check for a Save game directory config file and creates one with user input if does not exist

Echo.Type Your savegame directory below example (D:\Morrowind\Saves)
if not exist Savedir.cfg (
set /p svgdir=Save game directory in quotes or default=) Else goto body
set dir=%svgdir%
if /i "%svgdir%"=="" goto start
if /i "%svgdir%"=="default" set dir="%programfiles%\Bethesda Softworks\Morrowind\Saves"

Rem this line checks to see if user specified directory has any savegames if not displays message

cls
pushd %dir%
if not Exist *.ess (Echo.There Seems to be no savegames here is that Ok?) Else Goto DirCheck
set /p inp=[Y/N]:
if /i "%inp%"=="Y" goto DirCheck
if /i "%inp%"=="N" goto start
if /i "%inp%"=="Yes" goto DirCheck
if /i "%inp%"=="No" goto start

Rem This line checks to see if users specified directory is true if not displays error message and returns to start

:DirCheck
cls
popd
pushd %dir%
popd
if %ERRORLEVEL%==0 goto body else Echo Directory Not found!
pause
goto start
:body
pushd "%dtr%"
if not exist Savedir.cfg (Echo %dir%>Savedir.cfg) Else (for /F "Tokens=*" %%c in (Savedir.cfg) do set dir=%%c)
cls
popd
Rem These Lines speficify parsing variables

set B=
set C=

Rem These Lines List Current Profiles

Echo.To get profile list again type "List"
Echo.For a list of commands type "Help"
Echo.Known profiles are as listed below.
Echo.
for /F "tokens=*" %%a in (Profiles.cfg) do @echo %%a

Rem This line prompts user for commands

set /p ent=:

Rem These lines parses commands into Temporary tokens

:parsing
pushd "%dtr%"
del ent.cfg
Echo.%ent%>>ent.cfg
TIMEOUT -T 1 -Nobreak>nul
for /F "eol=  tokens=1,*" %%g in (ent.cfg) do (
set B=%%g) & (
set C=%%h)
popd

Rem These lines use above specified variables to desern witch command was prompted by the user

if /i "%B%"=="load" goto load
if /i "%B%"=="create" goto create
if /i "%B%"=="update" goto update
if /i "%B%"=="del" goto delete
if /i "%B%"=="list" goto list
if /i "%B%"=="help" goto help
if /i "%B%"=="whois" goto whois
if /i "%B%"=="ragequit" goto ragequit

Rem These lines "clean up" user input

if /i "%B%"=="" goto body
if /i "%B%"=="%B%" goto error

Rem These lines are the help script

:help
pushd "%dtr%"
del ent.cfg
popd
cls
Echo.To load a profile into the Saves directory type
Echo."load [insert profile name here]"
Echo.
Echo.To create a new profile type "Create [Insert Profile Name]"
Echo.
Echo.To use the currently loaded character under a specified
Echo.profile name type "Update [Insert profile here]"
Echo.
Echo.To delete a profile type "del [Insert profile here]"
Echo.
Echo.To display the profile that is currently in use type "whois"
Echo.
Echo.!!WARNING!! To destroy all profiles and saves type
Echo."RageQuit"
Echo.Note no Ctrl-z possiable
Echo.
Echo.To display this help section type "Help"
Pause
goto body

Rem These lines is the error display for incorrect commands

:error
pushd "%dtr%"
del ent.cfg
popd
echo.Not a known command. Type "help" for options!
pause
goto body

Rem these lines are the create script

:create
pushd "%dtr%"
Echo.%C%>Profiles.cfg
mkdir "%C%"
popd
pushd "%ptr%"
Echo.%C%>"%C%.cfg"
Echo."%C%" was created
Echo.Profile can now be loaded
popd
pause
pushd "%dtr%"
del ent.cfg
popd
goto body

Rem These lines are the load script

:load
robocopy "%dtr%\%C%" %dir% MOVE

I decided to make a profile manager for morrowind cause I don't have one, even though I could easily download one.  :)

The main problem thats stumping me right now is how to check for multiple instances of the same profile being made and display an error message warning the user, and Knowing what profile is currently loaded (I think I may have a solution for this)

A solution to checking for multiple instances of a profile could likely be solved with a for command likely resembling this

Code: [Select]
For /F "Tokens=*" %%i In ('findstr /B /ON [A text file containg a list of all made profiles]') do (Echo.%%i>%%i)
Something like that i'm really not sure

If you have suggestions I'm happy to hear them.  ;D
Thanks ahead of time.
Title: Re: A batch based profile manager GUI
Post by: foxidrive on July 26, 2014, 04:04:32 AM
Profiles.cfg is where all profiles are stored, correct?

What format is the data inside the file?   Can you include a sample list here in code tags?
Title: Re: A batch based profile manager GUI
Post by: millergram on July 26, 2014, 11:44:17 AM
Profiles.cfg is not in any particular format it is simply a plain text document listing all profiles in the order they were created